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 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
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)
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
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)
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)
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)
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)
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
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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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()
|
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.
|
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",
|
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...
|
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...
| |
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:
|
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'...
|
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...
|
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, ...);
}
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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
| |
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...
| |