DllImport issue in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: DllImport issue in C#

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    DllImport issue in C#

    Hi.

    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:

    Code:
    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.

    Code:
    [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
    Posts
    2

    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 online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center