473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem w/ returning char array from an unmanaged dll

1 New Member
have an unmanaged C++ DLL with following method:

the DLL interface for unmanaged C++ is:
SendCommand(void *h, char *c, char *d, char *b);

the declaration in C# is:
[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);

when i call the function
byte buf = new byte[25];
SendCommand(r, "test string", "", buf);

The problem is that buf should have a value in it when the call is completed. However buf is empty. I have another function which only accepts a byte array as the input and it is a char * on the c++ side and that returns valid values in the byte array. So I am guessing the problem could be with the passing of the strings as the SendCommand method will return correct values when it understands the strings correctly. The SendCommand method works correctly if I make the call using C++ code but does not work correctly from C#. Could be LPSTR not be working correctly as it is supposed to?

THANKS
Mar 23 '07 #1
0 1020

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1411
by: Krzysztof | last post by:
Hi! I have a class: some_class{ private: char* seq; public: some_class(char* se); char* ret_seq(); ....
11
6385
by: Marcus Jacobs | last post by:
Dear Group I have encountered a problem with fclose and I am wondering if anyone could provide some insight about this problem to me. Currently, I am working on a small personal project that is...
1
3304
by: john | last post by:
Relatively new to C coding, so any help would greatly be appreciated. I'm having problems try to return my string array from my parsing function. When I do a printf I am getting the correct value...
3
1834
by: Carramba | last post by:
hi! the code is cinpiling with gcc -ansi -pedantic. so Iam back to my question Iam trying to make program were I enter string and serach char. and funktion prints out witch position char is...
4
1648
by: Jon Skeet | last post by:
I've just noticed something rather odd and disturbing. The following code displays "True": using System; class Test { public static void Main(string args) { string x = new string...
2
11928
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
3
12219
by: Lee Crabtree | last post by:
I have a managed DLL that I've used to expose a C++ class. One of the functions in this class reads a line out of a file into a buffer of type "unsigned char*". Since all the data is just...
5
10013
by: Mark Ingram | last post by:
Hi, how can i return an array of strings from an unmanaged c++ dll into a c# application? cheers Mark
3
2055
by: =?Utf-8?B?QzBkM3I=?= | last post by:
have an unmanaged C++ DLL with following method: the DLL interface for unmanaged C++ is: SendCommand(void *h, char *c, char *d, char *b); the declaration in C# is: unsafe public static...
0
7136
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
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6906
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
7397
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
5490
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 project—planning, coding, testing,...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
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
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.