473,805 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling DLL function from C# and char** parameter type

I'm trying to call a dll function from C# which has the following form:

int some_function(i nt count, char **arg1, char **arg2)

Which parameter type I need to use in C# for C++ char** type? I tried
byte[][] (array of byte[]) but I get error "There is no marshaling support
for nested arrays."
regards
Tomaz
Jan 12 '08 #1
11 5681
Tomaz,

Are the strings being read from, or are they being written to? If they
are being read from, you should be able to pass it as an array of strings,
and it should work.

If they are being written to, then you will have to declare the
parameters as IntPtrs, allocate the memory for them, and then marshal the
data yourself (don't forget to unallocate the memory).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Siol" <un*****@abc.co mwrote in message
news:zL******** ***********@new s.siol.net...
I'm trying to call a dll function from C# which has the following form:

int some_function(i nt count, char **arg1, char **arg2)

Which parameter type I need to use in C# for C++ char** type? I tried
byte[][] (array of byte[]) but I get error "There is no marshaling support
for nested arrays."
regards
Tomaz
Jan 12 '08 #2
Siol wrote:
I'm trying to call a dll function from C# which has the following
form:

int some_function(i nt count, char **arg1, char **arg2)

Which parameter type I need to use in C# for C++ char** type? I tried
byte[][] (array of byte[]) but I get error "There is no marshaling
support for nested arrays."
Probably something like:

[DllImport(yourd llname, CharSet=CharSet .Ansi)]
public static extern int some_function(i nt count,
string[] arg1, string[] arg2);

--
Rudy Velthuis http://rvelthuis.de

"Everyone is a genius at least once a year; a real genius has his
original ideas closer together."
-- Georg Lichtenberg (1742-1799)
Jan 13 '08 #3
The strings are input parameters to the function (init parameters).

regards
Tomaz
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:D4******** *************** ***********@mic rosoft.com...
Tomaz,

Are the strings being read from, or are they being written to? If they
are being read from, you should be able to pass it as an array of strings,
and it should work.

If they are being written to, then you will have to declare the
parameters as IntPtrs, allocate the memory for them, and then marshal the
data yourself (don't forget to unallocate the memory).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Siol" <un*****@abc.co mwrote in message
news:zL******** ***********@new s.siol.net...
>I'm trying to call a dll function from C# which has the following form:

int some_function(i nt count, char **arg1, char **arg2)

Which parameter type I need to use in C# for C++ char** type? I tried
byte[][] (array of byte[]) but I get error "There is no marshaling
support for nested arrays."
regards
Tomaz

Jan 14 '08 #4
Tomaz Koritnik wrote:
The strings are input parameters to the function (init parameters).
Then (string[] arg1, string[] arg2) will do.

--
Rudy Velthuis http://rvelthuis.de

"Analyzing humor is like dissecting a frog. Few people are
interested and the frog dies of it."
-- E. B. White (1899-1985)
Jan 14 '08 #5
I tried with string[] but as soon as I call the function, whole application
terminates instantly with no error message. I haven't tried with
CharSet=CharSet .Ansi yet.

from MySQL specification the dll function looks like this: int
mysql_library_i nit(int argc, char **argv, char **groups)

my implementation:

[DllImport("libm ysqld.dll")]
private static extern int mysql_server_in it(int argc, string[] argv,
string[] groups);
{
string[] argv = new string[1];
argv[0] = "mysql_test ";
string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";
mysql_server_in it(0, argv, groups);
}

regards

Tomaz


"Rudy Velthuis" <ne********@rve lthuis.dewrote in message
news:xn******** ********@news.m icrosoft.com...
Tomaz Koritnik wrote:
>The strings are input parameters to the function (init parameters).

Then (string[] arg1, string[] arg2) will do.

--
Rudy Velthuis http://rvelthuis.de

"Analyzing humor is like dissecting a frog. Few people are
interested and the frog dies of it."
-- E. B. White (1899-1985)

Jan 14 '08 #6
TomazK wrote:
[DllImport("libm ysqld.dll")]
private static extern int mysql_server_in it(int argc, string[] argv,
string[] groups);
{
string[] argv = new string[1];
argv[0] = "mysql_test ";
string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";
mysql_server_in it(0, argv, groups);
}
Assuming that argc is an argument count, it should probably not be 0,
and assuming that to each arg there is a group, you should probably
have argc=2, and also have two (2)strings in each array:

{
string[] argv = new string[2];
argv[0] = "mysql_test ";
argv[1] = argv[0];

string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";

mysql_server_in it(2, argv, groups);
}

Of course, I have no idea which strings are valid. Try to convert a C
or C++ example, if you have one, to C#.

--
Rudy Velthuis http://rvelthuis.de

"The object of war is not to die for your country but to make
the other bastard die for his."
-- General George Patton (1885-1945)
Jan 14 '08 #7
Yes, argc is a count and it doesn't matter if I specify 2 or 0 or any other
number. It's the same in all cases.
regards
Tomaz
"Rudy Velthuis" <ne********@rve lthuis.dewrote in message
news:xn******** ********@news.m icrosoft.com...
TomazK wrote:
>[DllImport("libm ysqld.dll")]
private static extern int mysql_server_in it(int argc, string[] argv,
string[] groups);
{
string[] argv = new string[1];
argv[0] = "mysql_test ";
string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";
mysql_server_in it(0, argv, groups);
}

Assuming that argc is an argument count, it should probably not be 0,
and assuming that to each arg there is a group, you should probably
have argc=2, and also have two (2)strings in each array:

{
string[] argv = new string[2];
argv[0] = "mysql_test ";
argv[1] = argv[0];

string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";

mysql_server_in it(2, argv, groups);
}

Of course, I have no idea which strings are valid. Try to convert a C
or C++ example, if you have one, to C#.

--
Rudy Velthuis http://rvelthuis.de

"The object of war is not to die for your country but to make
the other bastard die for his."
-- General George Patton (1885-1945)

Jan 15 '08 #8
On Jan 14, 10:10 am, "TomazK" <unkn...@abc.co mwrote:
I tried with string[] but as soon as I call the function, whole application
terminates instantly with no error message. I haven't tried with
CharSet=CharSet .Ansi yet.

from MySQL specification the dll function looks like this: int
mysql_library_i nit(int argc, char **argv, char **groups)

my implementation:

[DllImport("libm ysqld.dll")]
private static extern int mysql_server_in it(int argc, string[] argv,
string[] groups);

{
string[] argv = new string[1];
argv[0] = "mysql_test ";

string[] groups = new string[2];
groups[0] = "libmysqd_serve r";
groups[1] = "libmysqd_clien t";

mysql_server_in it(0, argv, groups);

}
The function might expect groups and/or argv to be null-terminated.
Try adding an extra item to the end of each array and setting it to
null.

Jesse
Jan 17 '08 #9
Jesse McGrew wrote:
The function might expect groups and/or argv to be null-terminated.
Try adding an extra item to the end of each array and setting it to
null.
Could be. Good idea. But then I wonder what argc does there. <g>
--
Rudy Velthuis http://rvelthuis.de

"Wagner's music is better than it sounds."
-- Mark Twain (1835-1910)
Jan 17 '08 #10

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

Similar topics

6
1971
by: komal | last post by:
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is calling function can be anything. for example.suppose my function is function2. then when i call function1(int i ,char j,float d) { function2()
12
1522
by: Yuan Zhong | last post by:
Hi, Can someone please explain me what's going on during a call to a function. Specifically, I wanted to know what's going on in Stacks. Why is it ok to pass only 2 parameters or 5 parameters when the function prototype requires 3. thanks.
11
4740
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to create content to put at the address pointed to by f. In particular, I'd like to avoid/replace the memcpy line. Possible application (inspired by Paul Graham, "ANSI Common Lisp",
4
2787
by: Angel | last post by:
I'm trying to call a DLL function that receives as parameter a user-defined structure created by the company that made the dll. When I call the function from my main form, I call dllCalls.addVer("string1", "string2") -this is how I created the method in the class. Now, in this static method that uses DllImport to read the dll, I need to move "string1" and "string2" into a structure called PARMS_DIRS since the only way the dll function can...
8
1438
by: Johann Blake | last post by:
I need to call a C DLL function. The first parameter expects a pointer to a long. It returns a value at the address of the pointer. The second parameter expects a pointer to a pointer. It creates an array and returns the data it stores in this array. I have tried many different combinations of P/Invoke declarations and none have worked. When I step from my c# code into the c code, oNumRays points to 0x00000000 and when it attempts to...
2
2866
by: JoeB | last post by:
Hi Trying to call the following (c++) dll: void getVersionInfo( long p_lIndex, char* p_cVersionNumber, int p_iVersBufSize, char* p_cDescription, int p_iDescBufSize, BOOL& p_bCompulsory ); So, i do this:
2
2149
by: brian_harris | last post by:
I am tring to use trimstart to remove leading zeros, but all things I try give a compiler error on converting data. I am programing in C++ .net vs2003. This is one of my earlier attempts to call function empcode = empcode->TrimStart ('0'); This is result: c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(322): error C2664: 'System::String::TrimStart' : cannot convert parameter 1 from 'char' to '__wchar_t __gc'...
11
3203
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for Esa_Init. When I make a call, VS2005 reports "AccessViolationException" and refers to the 4th parameter (EsaT_State_Handle). I don't know how to define nor pass this reference correctly to the legacy DLL. What am I doing wrong? Thanks in...
8
2088
by: keith | last post by:
Someone please help me out here - I'm having a 'bad brain' day. I have a number of C logging functions, prototyped as, say: extern "C" { mylog1(char *arg1, char *arg2, char *arg3); mylog2(char *arg1, char *arg2, ...); mylog3(char *arg1, ...); }
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
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 we have to send another system
3
3008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.