I have a DLL that i'm interfacing with that's in C++. here's the interface
defn:
SendCommand(void *h, char *cmd, char *data, char *respbuffer);
here's the wrapper for the dll call in my C# code:
[DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
unsafe public static extern char* SendCommand(void* h,
[MarshalAs(UnmanagedType.LPStr)] string cmd, [MarshalAs(UnmanagedType.LPStr)]
string data, [MarshalAs(UnmanagedType.LPArray)] ref byte[] buffer);
and here's my function call:
//code here...
byte buf = new byte[25];
SendCommand(handle, "cmd string", "data", buf);
i think the cmd parameter is getting messed up when i marshal it as LPStr!!
am i doing something wrong? the reason i say this is i do not get any
response in the response buffer!!!
i could get the same function call working in C++ and i do see the response
in the buffer...can someone please help? 2 5454
"rkpat" <rk***@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
>I have a DLL that i'm interfacing with that's in C++. here's the interface
defn:
SendCommand(void *h, char *cmd, char *data, char *respbuffer);
here's the wrapper for the dll call in my C# code:
[DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
unsafe public static extern char* SendCommand(void* h,
[MarshalAs(UnmanagedType.LPStr)] string cmd, [MarshalAs(UnmanagedType.LPStr)]
string data, [MarshalAs(UnmanagedType.LPArray)] ref byte[] buffer);
and here's my function call:
//code here...
byte buf = new byte[25];
SendCommand(handle, "cmd string", "data", buf);
i think the cmd parameter is getting messed up when i marshal it as LPStr!!
am i doing something wrong? the reason i say this is i do not get any
response in the response buffer!!!
i could get the same function call working in C++ and i do see the response
in the buffer...can someone please help?
Why the char* in :
extern char* SendCommand
there is no return defined in your C function.
Try this:
DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
public static extern void SendCommand(IntPtr h, string cmd, string data, StringBuilder
buffer);
IntPtr handle = ....;
StringBuilder buf = new StringBuilder(25);
SendCommand(handle, ....);
Willy.
thanks for the reply Willy.
actually, the sendcommand function looks like this (my bad - typo)
char * SendCommand(void *h, char *cmd, char *data, char *respbuffer);
i'll try the recommended changes and will let u know how it goes. THANKS.
"Willy Denoyette [MVP]" wrote:
"rkpat" <rk***@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
I have a DLL that i'm interfacing with that's in C++. here's the interface
defn:
SendCommand(void *h, char *cmd, char *data, char *respbuffer);
here's the wrapper for the dll call in my C# code:
[DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
unsafe public static extern char* SendCommand(void* h,
[MarshalAs(UnmanagedType.LPStr)] string cmd, [MarshalAs(UnmanagedType.LPStr)]
string data, [MarshalAs(UnmanagedType.LPArray)] ref byte[] buffer);
and here's my function call:
//code here...
byte buf = new byte[25];
SendCommand(handle, "cmd string", "data", buf);
i think the cmd parameter is getting messed up when i marshal it as LPStr!!
am i doing something wrong? the reason i say this is i do not get any
response in the response buffer!!!
i could get the same function call working in C++ and i do see the response
in the buffer...can someone please help?
Why the char* in :
extern char* SendCommand
there is no return defined in your C function.
Try this:
DllImport("test.dll", CharSet = CharSet.Ansi, EntryPoint = "SendCommand")]
public static extern void SendCommand(IntPtr h, string cmd, string data, StringBuilder
buffer);
IntPtr handle = ....;
StringBuilder buf = new StringBuilder(25);
SendCommand(handle, ....);
Willy.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew Cumming |
last post by:
I am having trouble using Platform Invoke to call C++ DLLs
from C# windows applications. The DLLs seem to load, but I
get run-time errors to the effect that the named entry
points cannot be found....
|
by: Bryan |
last post by:
I have a multi-threaded C# console application that uses WMI
(System.Management namespace) to make RPC calls to several servers (600+ )
and returns ScheduledJobs. The section of my code that...
|
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...
|
by: Jesse McGrew |
last post by:
Hi all,
I'm trying to make a plugin DLL for a third-party application, using
VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of
the application, and my actual plugin code...
|
by: sklett |
last post by:
I'm having a really hard time with wrapping an unmanaged class with a
managed class, then calling that managed class from my C# code.
I will show you the three pieces, then explain:
--------...
|
by: H.B. |
last post by:
Hi,
I need to make a function that can display data on my Managed C++ app and be
called by an unmanaged C++ DLL. Something like :
void Form1::Form1_Load(System::Object * sender,...
|
by: MC-Advantica |
last post by:
Does anyone have a simple "Hello World" like application that demonstrates
unmanaged C++ calling managed C++ developed in VS2005? I'm confused by many
posts as they discuss managed extensions from...
|
by: Amit Dedhia |
last post by:
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for...
|
by: Arne Adams |
last post by:
Hi,
I try to use a C# Dialog in a legacy MFC application.
The problem seems to boil down to the following:
from an unmanaged console application I can call any function of the managed
bridge - if...
|
by: Klaus |
last post by:
Hi,
I have an existing VC 6 MFC application which communicates asynchronly with
a VC 2005 managed code dll.
I use an unmanaged base class with virtual functions to access methods in
the MFC...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |