从C#和char **参数类型调用DLL函数 [英] Calling DLL function from C# and char** parameter type

查看:100
本文介绍了从C#和char **参数类型调用DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从C#调用一个具有以下形式的dll函数:


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


我需要在C#中为C ++ char **类型使用哪种参数类型?我试过

byte [] [](byte []数组)但我收到错误没有编组支持

嵌套数组。

问候

Tomaz

解决方案

Tomaz,


字符串是从中读取还是被写入?如果他们正在读取
,你应该能够将它作为一个字符串数组传递,

它应该可以工作。


如果要写入,则必须将

参数声明为IntPtrs,为它们分配内存,然后自行封送

数据(不要忘记取消分配内存。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

" Siol" < un ***** @ abc.com在留言中写道

新闻:zL ******************* @ news.siol.net ...


我正在尝试从C#调用dll函数,其格式如下:


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

我需要在C#中为C ++ char **类型使用哪种参数类型?我试过

byte [] [](byte []数组)但我收到错误没有编组支持

嵌套数组。


问候

Tomaz


Siol写道:


我正试图从C#调用一个dll函数,它具有以下

形式:


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

我需要在C#中为C ++ char **类型使用哪种参数类型?我试过

byte [] [](byte []数组)但是我得到错误没有编组

支持嵌套数组。



可能类似于:


[DllImport(yourdllname,CharSet = CharSet.Ansi)]

public static extern int some_function(int count,

string [] arg1,string [] arg2);


-

Rudy Velthuis http://rvelthuis.de


每个人至少每年都有一次天才;一个真正的天才让他的原始想法更加紧密。

- Georg Lichtenberg(1742-1799)


< blockquote>字符串是函数的输入参数(init参数)。


问候

Tomaz

" Nicholas Paldino [ .NET / C#MVP]" < mv*@spam.guard.caspershouse.com写在

消息新闻:D4 ************************* ********* @ microsof t.com ...


Tomaz,


是字符串被读取或被写入?如果他们正在读取
,你应该能够将它作为一个字符串数组传递,

它应该可以工作。


如果要写入,则必须将

参数声明为IntPtrs,为它们分配内存,然后自行封送

数据(不要忘记取消分配内存。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

" Siol" ; < un ***** @ abc.com在留言中写道

新闻:zL ******************* @ news.siol.net ...


>我正在尝试从C#调用dll函数,其格式如下:

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

我需要在C#中使用哪种参数类型为C ++ char **类型?我试过了
byte [] [](byte []数组),但是我得到错误没有编组支持嵌套数组。

问候
Tomaz



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

int some_function(int 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,

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.com

"Siol" <un*****@abc.comwrote in message
news:zL*******************@news.siol.net...

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

int some_function(int 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(int 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(yourdllname, CharSet=CharSet.Ansi)]
public static extern int some_function(int 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.comwrote in
message news:D4**********************************@microsof t.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.com

"Siol" <un*****@abc.comwrote in message
news:zL*******************@news.siol.net...

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

int some_function(int 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



这篇关于从C#和char **参数类型调用DLL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆