some marshalling questions

    Date: 01/25/06 (C Sharp)    Keywords: no keywords

    Okay, this sort of crosses between C# and Managed C++, but it's valid either way. Here goes.

    I'm working on the application side of a project (the other side is the hardware stuff). The hardware is used to interface with stuff across a connection. It uses a struct something like this to move info to and from the app:

    struct COMMAND_MSG
    {
    int msgID;
    int msgLength;
    char *opCodes;
    short range;
    };

    Pretty simple. So, on the app side, I define a matching .NET type:

    __value __gc public struct M_COMMAND_MSG
    {
    System::Int32 msgID;
    System::Int32 msgLength;
    System::Byte opCodes[];
    System::Int16 range;
    };

    Here's where the problem comes in. I can't figure out how to marshal this type so that an unmanaged function could map it into the unmanaged struct type. Marshaling the type into a buffer I can pass as a void* is pretty simple, normally, involving something of this ilk:

    IntPtr buffer = Marshal::AllocHGlobal(64);
    Marshal::StructureToPtr(__box(testStruct), buffer, true);

    That gives me a buffer that I can shoot to an unmanaged function (as buffer.ToPointer()). But with that array, something isn't happening properly. When the buffer gets to the unmanaged function, the unmanaged type isn't mapped correctly.

    What am I doing wrong?

    DC

    Source: http://community.livejournal.com/csharp/47782.html

« Drawing a line on a form. || So yeah... stuff is hard »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home