1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Marshal variable length arguments?

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

  1. stitts

    stitts New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:

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


    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, "", 10)

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

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

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


Share This Page