473,408 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to DllImport function with "char**" parameter

Excuse me!!

I have a DLL file named "TESTDLL.DLL".
In TESTDLL.DLL
export function :
void GetPChar(char** pstr);

In .NET C# ,
How to call "GetPChar(char** pstr)" function ?

Thanks!!
Nov 15 '05 #1
3 14520
Dennis,
Excuse me!!

I have a DLL file named "TESTDLL.DLL".
In TESTDLL.DLL
export function :
void GetPChar(char** pstr);

In .NET C# ,
How to call "GetPChar(char** pstr)" function ?


What does the function do? If it returns a single string pointer, try
it like this

[DllImport("testdll.dll")]
static extern void GetPChar(out IntPtr pstr);

---
IntPtr pstr;
GetPChar(out pstr);
string s = Marshal.PtrToStringAnsi(pstr);

Then you might have to free the returned buffer somehow, depending on
how its allocated by the DLL.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
Dear Mattias Sjögren :

Thanks for your answer.

But "char** pstr" is a string array.
Such as
pstr[0] ---> string a
pstr[1] ---> string b
pstr[2] ---> string c

In C# ,
How to declare and call it ?

Thanks a lot!
"Mattias Sjögren" <ma********************@mvps.org>
???????:uz**************@TK2MSFTNGP12.phx.gbl...
Dennis,
Excuse me!!

I have a DLL file named "TESTDLL.DLL".
In TESTDLL.DLL
export function :
void GetPChar(char** pstr);

In .NET C# ,
How to call "GetPChar(char** pstr)" function ?


What does the function do? If it returns a single string pointer, try
it like this

[DllImport("testdll.dll")]
static extern void GetPChar(out IntPtr pstr);

---
IntPtr pstr;
GetPChar(out pstr);
string s = Marshal.PtrToStringAnsi(pstr);

Then you might have to free the returned buffer somehow, depending on
how its allocated by the DLL.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #3
"Dennis" <ry**@ms6.hinet.net> wrote in message
But "char** pstr" is a string array.
Such as
pstr[0] ---> string a
pstr[1] ---> string b
pstr[2] ---> string c
In C# ,
How to declare and call it ?


Here's how I would do it [warning: haven't tested the code below]

[DllImport("testdll.dll")]
static extern void GetPChar(out IntPtr pstr);

string[] ret = new string[count];
IntPtr str;
GetPChar(str);
for(int i = 0; i < count; i++) {
ret[i] = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(str, i *
IntPtr.Size));
}

The above code asumes you know the number of items in the returned array
['count'] in advance.

Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
Nov 15 '05 #4

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

Similar topics

2
by: John Eskie | last post by:
Hello, I've seen in some programs that they provide functions which has the following prototype: char *func1(); However I'm not sure it's safe. If the char array beeing returned is a local...
12
by: Vaca Louca | last post by:
Hello, I write an ISAPI authentication module which uses Berkeley DB and want it to be as efficient as possible. Both ISAPI and BerkeleyDB use arrays of chars (char *) to pass and receive...
4
by: John Devereux | last post by:
Hi, I would like some advice on whether I should be using plain "chars" for strings. I have instead been using "unsigned char" in my code (for embedded systems). In general the strings contain...
1
by: halise | last post by:
hello, i am trying to wrap an unmanaged C++ code to managed one so that i can use it within c#, and i am using IJW - "It Just Works" - method for that. In the code, there is a function which...
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
14
by: Anna | last post by:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
0
by: Ben Voigt [C++ MVP] | last post by:
Chip Gore wrote: Actually, because you are using the C++/CLI compiler, microsoft.public.dotnet.languages.vc is the most appropriate place to discuss this. To be useful from C# and other .NET...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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 project—planning, coding, testing,...
0
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...

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.