473,466 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

wrapper for unmanaged c++ DLL

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
Jan 8 '08 #1
3 3884

"Chris Bruckner" <Si****@gmx.dewrote in message
news:f5**********************************@q77g2000 hsh.googlegroups.com...
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

Jan 8 '08 #2
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);
}
}
}
Jan 9 '08 #3

"Chris Bruckner" <Si****@gmx.dewrote in message
news:83**********************************@h11g2000 prf.googlegroups.com...
>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);
}
}
}

Jan 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JRoe | last post by:
Hello, I am beside myself with this problem. I need to access unmanged C++ code in a C# environment. I have created a managed C++ wrapper that wraps the unmanaged class. When I call the...
0
by: Ola Sprauten | last post by:
I got a .NET class library project where I have written a managed wrapper for some unmanaged code. The managed wrapper is then used by a c# .net application. The problem I am having is that the...
1
by: | last post by:
Hi, I am making a wrapper class so I can call unmanaged classes from C#, I have these structs that I want to pass and get back from the unmanaged classes, do I... 1) Create a copy of these...
1
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an...
0
by: DotNetJunkies User | last post by:
Background: I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below: Range r = new Range( 2, 2 ); r = new Cell( “Hello Mum” ); Range is a...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
3
by: WithPit | last post by:
I am trying to create an managed wrapper but have some problems with it by using abstract classes. In my unmanaged library code i had the following three classes with the following hierarchy ...
4
by: bidalah | last post by:
Hi all, Basically I need to create a managed wrapper for the class "A" below: class A : public CModule { public: A(B& bees); virtual ~A();
4
by: devmentee | last post by:
I want to write a managed wrapper( kind of proxy) which will call into unmanaged C++ code. I've got a general idea and have read some articles on how to do it. But I cannot find any information on...
2
by: =?Utf-8?B?cGh5cw==?= | last post by:
I need to write a C# application that uses unmanaged C++ code. I created a C++/CLI wrapper to C++ code and encountered the following problem. Any time I try to instantiate a wrapper in C#...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.