none
Get Variable length array from c dll RRS feed

  • Question

  • Hello friends,

    I am developing some code where I need to deal with C/C++ dll.


    Problem Defination:

    1. To generate variable length array at unmanaged environment. 

    2. Get it in the c# application to display it to console.

    3. Call this function called "Read" multiple times in c#(managed env.).

    4. Get the data with different size on each call.

    5. Use pinning.

    Can anybody help me as I haven't work much on this kind of problems??

    Thanks in advance.

    Santosh.
    Thursday, October 1, 2009 6:19 AM

Answers

  • Hello again,


    I have got answer to my problem I managed to read data of different sizes with pinning.

    The solution which helped me, is here

     Visual C# Forums > Visual C# General > How to obtain from c# a unmanaged c++ out BYTE* parameter

    To extend it more the code which I wrote was like this,


    gc =

    GCHandle.Alloc(data, GCHandleType.Pinned);    // 'data' is an array whose size I got through dll 1st.

    ptrToData = gc.AddrOfPinnedObject();                   // ptrToData' is IntPtr to copy adress of pinned object.

    GetData(

    out ptrToData);                                     // 'GetData' method to get data from dll

    Marshal

     

    .Copy(ptrToData , data, 0, Size);               // Copy data.


    Santosh.
    • Marked as answer by santoshdarekar Thursday, October 1, 2009 9:16 AM
    Thursday, October 1, 2009 9:16 AM