1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

Calling unmanged DLL function with complex struct as parameters

Discussion in 'Microsoft News' started by NewsBot, Apr 1, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    What would be the porper way to call
    MyFunc(int, int, Struct2*) which is in unmanaged DLL from C# code?

    Where
    Struct2
    {
    int
    int
    Struct1[SOME_CONST]
    }

    or
    {
    int
    int
    Struct1*
    }

    I've tried to define STRUCT2 in managed code as
    <!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo-->[<!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#2b91af--><span style="color:#2b91af <!--/coloro-->StructLayout<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo-->(<!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#2b91af--><span style="color:#2b91af <!--/coloro-->LayoutKind<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo-->.Sequential)]
    <!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->public<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->struct<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#2b91af--><span style="color:#2b91af <!--/coloro-->STRUCT2<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo-->
    {
    <!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->public<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#2b91af--><span style="color:#2b91af <!--/coloro-->int<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--> XINT;
    <!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->public<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->int<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--> YINT;
    <!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#008000--><span style="color:#008000 <!--/coloro-->[MarshalAs(UnmanagedType.LPStruct, SizeConst = SOME_CONST)]
    <!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#0000ff--><span style="color:#0000ff <!--/coloro-->public<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo--><!--coloro:#008000--><span style="color:#008000 <!--/coloro-->STRUCT1[]<!--colorc--><!--/colorc--><!--sizec--><!--/sizec--><!--sizeo:2--><span style="font-size:10pt;line-height:100% <!--/sizeo-->someStruct;
    }

    and then calling

    STRUCT2 myStruct2;*
    MyFunc(someInt, someOtherInt, myStruct2);


    but looks like LPStruct is reserved for some misterious use (MSDN articles/help didn't help much).

    Any ideas?
    <!--sizec--><!--/sizec-->



     

Share This Page