wrapper for unmanaged c++ DLL

Discussion in 'Microsoft C# .NET' started by Chris Bruckner, Jan 8, 2008.

  1. Hi,

    I have trouble with a C# wrapper for an unmanaged DLL. The code is:

    int WINAPI DcpDll_GetFoundDevices
    (int piIdx, /*[in] Device index in the internal
    list(0..MAX_MEMBER)*/
    char far *psName, /*[out] Device Name*/
    char far *psIP, /*[out] Device Ip Address*/
    char far *psSubnet,/*[out] Device Subnet Mask*/
    char far *psMAC, /*[out] Device MAC Address*/
    char far *psType) /*[out] Device Type*/

    So far all I've got is:
    [DllImport("DcpDll.dll")]
    private static extern int DcpDll_GetFoundDevices
    (int piIdx, ?? psName, ?? psIP, ?? psSubnet, ??
    psMAC, ?? psType);

    I just can't figure out how to do these char far* in C#. Can somebody
    help? I'm getting desperate here.

    Yours,
    Chris
     
    Chris Bruckner, Jan 8, 2008
    #1
    1. Advertisements

  2. "Chris Bruckner" <> wrote in message
    news:...
    > Hi,
    >
    > I have trouble with a C# wrapper for an unmanaged DLL. The code is:
    >
    > int WINAPI DcpDll_GetFoundDevices
    > (int piIdx, /*[in] Device index in the internal
    > list(0..MAX_MEMBER)*/
    > char far *psName, /*[out] Device Name*/
    > char far *psIP, /*[out] Device Ip Address*/
    > char far *psSubnet,/*[out] Device Subnet Mask*/
    > char far *psMAC, /*[out] Device MAC Address*/
    > char far *psType) /*[out] Device Type*/
    >
    > So far all I've got is:
    > [DllImport("DcpDll.dll")]
    > private static extern int DcpDll_GetFoundDevices
    > (int piIdx, ?? psName, ?? psIP, ?? psSubnet, ??
    > psMAC, ?? psType);
    >
    > I just can't figure out how to do these char far* in C#. Can somebody
    > help? I'm getting desperate here.


    You should be passing byte arrays... don't know what size the name or type
    should be but I'd guess the IP address and subnet mask are both 4 bytes and
    the MAC address is 6, unless they're in ASCII text format in which case give
    16 bytes for IP address and subnet mask and 18 bytes for MAC address.

    >
    > Yours,
    > Chris
     
    Ben Voigt [C++ MVP], Jan 8, 2008
    #2
    1. Advertisements

  3. > You should be passing byte arrays... don't know what size the name or type
    > should be but I'd guess the IP address and subnet mask are both 4 bytes and
    > the MAC address is 6, unless they're in ASCII text format in which case give
    > 16 bytes for IP address and subnet mask and 18 bytes for MAC address.


    It's ASCII text format.

    Still got an "A call to PInvoke function
    'DCPConnector::DcpDll_GetFoundDevices' has unbalanced the stack."
    error.

    What I've got now:
    [DllImport("DcpDll.dll", CharSet=CharSet.Ansi)]
    private static extern int DcpDll_GetFoundDevices
    (int piIdx,
    byte[] psName,
    byte[] psIP,
    byte[] psSubnet,
    byte[] psMAC,
    byte[] psType);

    public void GetDeviceList(Boolean save)
    {
    int MAX_MEMBER = 500;
    int iReturn;
    byte[] sName = new byte[260];
    byte[] sIP = new byte[16];
    byte[] sSubnet = new byte[16];
    byte[] sMAC = new byte[18];
    byte[] sType = new byte[260];

    for (int i = 0; i < MAX_MEMBER; i++)
    {
    if (save)
    {
    iReturn = DcpDll_GetFoundDevices(i, sName,
    sIP, sSubnet, sMAC, sType);
    }
    }
    }
     
    Chris Bruckner, Jan 9, 2008
    #3
  4. "Chris Bruckner" <> wrote in message
    news:...
    >> You should be passing byte arrays... don't know what size the name or
    >> type
    >> should be but I'd guess the IP address and subnet mask are both 4 bytes
    >> and
    >> the MAC address is 6, unless they're in ASCII text format in which case
    >> give
    >> 16 bytes for IP address and subnet mask and 18 bytes for MAC address.

    >
    > It's ASCII text format.
    >
    > Still got an "A call to PInvoke function
    > 'DCPConnector::DcpDll_GetFoundDevices' has unbalanced the stack."
    > error.


    I would specify the calling convention explicitly. You showed the C header
    using WINAPI, which would be CallingConvention.StdCall.

    >
    > What I've got now:
    > [DllImport("DcpDll.dll", CharSet=CharSet.Ansi)]
    > private static extern int DcpDll_GetFoundDevices
    > (int piIdx,
    > byte[] psName,
    > byte[] psIP,
    > byte[] psSubnet,
    > byte[] psMAC,
    > byte[] psType);
    >
    > public void GetDeviceList(Boolean save)
    > {
    > int MAX_MEMBER = 500;
    > int iReturn;
    > byte[] sName = new byte[260];
    > byte[] sIP = new byte[16];
    > byte[] sSubnet = new byte[16];
    > byte[] sMAC = new byte[18];
    > byte[] sType = new byte[260];
    >
    > for (int i = 0; i < MAX_MEMBER; i++)
    > {
    > if (save)
    > {
    > iReturn = DcpDll_GetFoundDevices(i, sName,
    > sIP, sSubnet, sMAC, sType);
    > }
    > }
    > }
     
    Ben Voigt [C++ MVP], Jan 9, 2008
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver

    Info-zip's unzip32.dll Wrapper functions for C#?

    Oliver, Jul 22, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    584
    Nicholas Paldino [.NET/C# MVP]
    Jul 22, 2003
  2. Youseful Software

    *IMPORTANT* update of the C# wrapper for msi.dll

    Youseful Software, Jul 22, 2003, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    672
    Youseful Software
    Jul 22, 2003
  3. Greg Ewing [MVP]

    Re: DLL wrapper

    Greg Ewing [MVP], Sep 18, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    191
  4. Joe
    Replies:
    0
    Views:
    201
  5. Peted
    Replies:
    0
    Views:
    312
    Peted
    Apr 18, 2007
Loading...

Share This Page