none
New to unmanaged stuff - import a function that expects a void** ? RRS feed

  • Question

  • Since I am absolutely new to unmanaged and DllImport and stuff, please explain like I was your grandpa! ^^

    How do I use this function

    DWORD WINAPI Foo(_In_out_ void** handle);
    from managed code?

    Thanks in advance!

    Monday, October 1, 2018 10:28 AM

All replies

  • I'm afraid it is unrealistic to assume we can explain something that is reasonably advanced without any knowledge of where you are at.

    Do you know the difference between managed and unmanaged code?

    Do you know how the CLR manages memory?

    How comfortable are you with C++?

    How about pointers and double pointers?

    Do you know what void** is in C++ code?

    How comfortable are you with C# in general?

    Do you know what IntPtr is used for?

    If you don't already have a good understanding of C# then I strongly recommend that you get comfortable with it first before you try to tackle interop code. Without an understanding of C# and how the CLR works then an explanation of the interop could would be meaningless. Having a good understanding of C++ would be a benefit as well but not critical to making interop calls.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, October 1, 2018 3:06 PM
    Moderator
  • Hello C. Posingies,

    1. A void* in C/C++ is a generic pointer. It is usually represented in C# as an IntPtr type.

    2. Hence a void** in C/C++ would be a pointer to a pointer.

    3. One way to express the function Foo() in C# is as follows :

    [DllImport("SomeDLL.dll", CallingConvention = CallingConvention.StdCall)]
    private static extern UInt32 Foo(ref IntPtr handle);
    

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Monday, October 1, 2018 3:13 PM
  • Knowing the correct syntax for P/Invoke is only part of the equation.

    Do you know what the C++ function you are calling expects to receive?   After all, a void* pointer (generic pointer) could point at ANYTHING.  And a void** pointer to a pointer just adds a level of indirection.

    And assuming that you know what the C++ function expects to receive do you know how to marshal that data to unmanaged memory?

    Wednesday, October 3, 2018 1:54 PM
  • I'm afraid it is unrealistic to assume we can explain something that is reasonably advanced without any knowledge of where you are at.

    Do you know the difference between managed and unmanaged code?

    Do you know how the CLR manages memory?

    How comfortable are you with C++?

    How about pointers and double pointers?

    Do you know what void** is in C++ code?

    How comfortable are you with C# in general?

    Do you know what IntPtr is used for?

    If you don't already have a good understanding of C# then I strongly recommend that you get comfortable with it first before you try to tackle interop code. Without an understanding of C# and how the CLR works then an explanation of the interop could would be meaningless. Having a good understanding of C++ would be a benefit as well but not critical to making interop calls.


    Michael Taylor 

    As I told you, you don't understand C/C++.

    Notice, please: there isn't a single thing that is specific to C++ in the original question.

    So, why did you mention C++?...

    Thursday, October 4, 2018 9:05 PM