Marshal variable length arguments?

Discussion in 'C++' started by stitts, Aug 28, 2010.

  1. stitts

    stitts New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey,

    I am new to managed C++ and I have been struggling to find any information on this.

    Background:

    Need to develop a managed c++ "proxy" library to interface with a unmanaged c++ library so managed code can reuse same library. The unmanaged library is a logging library that has predefined format strings with variable arguments (of any kind). For example: Log 1 Description = "Unable to connect to %s. Connect tries: %d". We use vsprintf on these predefined strings with variable length arguments passed in to form the final log fields.

    When I pass in the variable arguments to the managed c++ code, everything looks fine, but when I pass it directly into the unmanaged function, the wrong values are appearing. Is there any special marshaling I am supposed to be doing to the data? Note that the variable arguments might not necessarily be the same type as each other (unless each predefined string is changed).

    So brief sudo code (omitted proper syntax):

    Log 1 Description = "Unable to connect to %s. Connect tries: %d".

    C# App:
    ManagedLogger.Log(LogId = 1, "1.1.1.1", 10)

    Managed C++ Lib:
    ManagedLogger::Log(int Id, ...array ^ args)
    {
    UnmanagedLogger::Log(Id, args)
    }

    Unmanaged C++ Lib:
    UnmanagedLogger::Log(int Id, ...)
    {
    va_list argumentList;
    va_start()
    char* format = Log 1 Description;
    vsprintf(format, argumentList);
    va_end()
    }

    Any idea why my va_list is not getting the right data?

    Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice