PC Review


Reply
Thread Tools Rate Thread

wrapper for unmanaged c++ DLL

 
 
Chris Bruckner
Guest
Posts: n/a
 
      8th Jan 2008
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
 
Reply With Quote
 
 
 
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      8th Jan 2008

"Chris Bruckner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Chris Bruckner
Guest
Posts: n/a
 
      9th Jan 2008
> 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:cpDll_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);
}
}
}
 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      9th Jan 2008

"Chris Bruckner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> 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:cpDll_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);
> }
> }
> }



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Deploying unmanaged DLL with managed wrapper adebaene@club-internet.fr Microsoft VC .NET 2 19th May 2008 09:02 AM
automagicaly generate a wrapper for unmanaged dll or library Peted Microsoft C# .NET 0 18th Apr 2007 09:33 AM
Giving one managed wrapper class access to the unmanged part of another managed wrapper class mschuck Microsoft VC .NET 1 31st Aug 2006 05:27 PM
Creating an unmanaged wrapper to C# Library Brandon Langley Microsoft VC .NET 0 28th Oct 2003 08:41 PM
Firing events from within unmanaged code into a managed wrapper Kieran Benton Microsoft VC .NET 0 29th Jul 2003 01:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 AM.