CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2013

    DllImport issue in C#


    I need some help on importing a (probably unmanaged) C++ dll. From that specific dll, I only have a header file and a dll.
    In the header the following is declared:

    typedef struct Device_ *DeviceHandle;
    API ResultType GetDevices(DeviceHandle **devices, UInteger *count);
    The definition of Device_ is unknown to me. (It's not in the header file)

    I tried the following in C# and it's not giving me an error, but I also don't get a device list and count equals one, even if there are two registered devices connected.

    [DllImport("SomeDLL.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern ErrorType GetDevices(out IntPtr devices, out UInt32 count);
    var devices = new IntPtr();
    UInt32 count = 0;
    var result = I1_GetDevices(out devices, out count);
    I also have no idea how to use or cast the list of devices.

    I appreciate your help!

  2. #2
    Join Date
    Sep 2013

    Re: DllImport issue in C#

    Small addition: it's not C++ but ANSI C99 and Device_ is an opaque struct, so I don't have to use the contents of it, but only use it as an input for other methods

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: DllImport issue in C#

    See pinvoke.net for pinvoke examples.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.