C# - 从C ++ Dll接收数据的问题 [英] C# - Problem to receive data from a C++ Dll

查看:46
本文介绍了C# - 从C ++ Dll接收数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个C#程序,想要调用一个dll,但是从dll接收

数据有问题。 />

dll声明如下:

" extern" C" void GetSN(TCHAR ** pData)"


Dll调用如下:

[DllImport(" mydll.dll")]

private static extern void GetSN(ref string [] val1);

....

string [] valueStr = new string [6];

....

GetSN(ref valueStr);


我有以下错误:

"发生了一个非托管异常:''System.NotSupportedException''"


有没有人知道这个问题?

谢谢你提前回答。

Hi,

I have a C# program and want to call a dll, but have problem to receive the
data from the dll.

The dll declaration is the following :
"extern "C" void GetSN(TCHAR** pData)"

The Dll call is the following :
[DllImport("mydll.dll")]
private static extern void GetSN(ref string[] val1);
....
string[] valueStr = new string[6];
....
GetSN(ref valueStr);

I have the following error :
"An unmanaged exception was happened : ''System.NotSupportedException''"

Does anybody have an idea of the problem ?
Thanks in advance for any answer.

推荐答案

我对此不太确定,但你确定你可以换一个字符串

数组到一个char数组?


这是我从你的代码中看到的:

" extern" C" void GetSN(TCHAR ** pData)" < - 指向一个TCHAR

数组

string [] valueStr = new string [6]; < - 一个字符串数组

....

GetSN(ref valueStr)< - 你正在通过引用发送一个字符串数组

(指向指向字符的指针的指针......)


异常表示不支持调用的方法。

基本上,它没有识别你的功能GetSN。


就像我说的,我不确定这一点。但你可以查看你的

代码并验证这一点。

I''m not too sure about this, but are you sure you can convert a string
array to a single char array?

This is what I see from your code:
"extern "C" void GetSN(TCHAR** pData)" <--takes a pointer to a TCHAR
array

string[] valueStr = new string[6]; <-- a string array
....
GetSN(ref valueStr) <-- you''re sending a string array by reference
(pointer to a pointer to a pointer to a character....)

The exception means that the invoked method is not supported.
Basically, it is not recognising your function GetSN.

Like I said, I''m not certain about this. But you can look into your
code and verify this.





你可能是对的,但我不知道我可以使用哪种类型的变量。


我也问我别的东西:我正在使用的dll是嵌入式Visual C ++ 3.0创建的一个dll,我希望在Pocket PC 2003上使用它。

设备......

我知道eVC ++ 3.0与Pocket PC 2002兼容,但我不知道它是否与Pocket PC 2003兼容。


Tegdeep写道:
Hi,

You are probably right but I don''t know which type of variable I can use.

I''m asking me something else also : the dll I''m using is a dll which was
created by embedded Visual C++ 3.0 and I want to use it on a Pocket PC 2003
device....
I know that eVC++3.0 is compatible with Pocket PC 2002 but I don''t know if
it''s compatible with Pocket PC 2003.

"Tegdeep" wrote:
我对此不太确定,但你确定你可以将字符串
数组转换为单个字符数组吗?
externC" void GetSN(TCHAR ** pData)" < - 指向一个TCHAR
数组

string [] valueStr = new string [6]; < - 一个字符串数组
....
GetSN(ref valueStr)< - 你正在通过引用发送一个字符串数组
(指向指针的指针)一个字符....)

异常意味着不支持调用的方法。
基本上,它不能识别你的函数GetSN。

喜欢我说,我不确定这个。但你可以查看你的代码并验证这一点。
I''m not too sure about this, but are you sure you can convert a string
array to a single char array?

This is what I see from your code:
"extern "C" void GetSN(TCHAR** pData)" <--takes a pointer to a TCHAR
array

string[] valueStr = new string[6]; <-- a string array
....
GetSN(ref valueStr) <-- you''re sending a string array by reference
(pointer to a pointer to a pointer to a character....)

The exception means that the invoked method is not supported.
Basically, it is not recognising your function GetSN.

Like I said, I''m not certain about this. But you can look into your
code and verify this.



我认为你可以使用char类型变量而且它'当你调用这个函数时,我会把一个转换为

本身转换为TCHAR。 eVC ++ 3.0应该与PocketPC2003兼容



祝你好运。

I think you can use a char type variable and it''ll do a conversion by
itself to TCHAR when you call the function. eVC++3.0 should be
compatible with PocketPC2003.

Good Luck.


这篇关于C# - 从C ++ Dll接收数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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