一个转换过程号角宣言C#的DllImport [英] Convert a Clarion Procedure Declaration to C# DLLImport

查看:190
本文介绍了一个转换过程号角宣言C#的DllImport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换这种号角过程声明为C#?这是一个第三方DLL用C写的,这没有什么太大的文档的一部分。我所列举的原型号角的方法是否正常工作。在C#中,我不知道用什么类型来代替 * CString的。我试图的char [] 像@DanielC建议,但没有奏效。我还发现,号角是32位的(感谢@ shf301)



号角:



  sendRequest将程序(* CString的XDATA,龙DATALEN,龙xTimeout),字节,虚拟

C#(我已经试过,不工作):

 函数[DllImport(3RD_PARTY_API.dll)] 
私人静态外部长sendRequest将(REF串XDATA,诠释DATALEN,诠释xTimeout);

当我把在C#中 sendRequest将方法我得到检测标准 PInvokeStackImbalance从错误VS2010。我认为它的参数类型的问题,而不是像字符集入口点中的的DllImport声明。我真的只是停留在如何转换 * CString的来有效的C#类型。


解决方案<我/ DIV>

我找到了答案。我希望我仍然是谁写的代码,所以我可以大声喝斥开发工作。他们把一个包装周围的API,以便我与3个参数中列出的方法,然后调用无超时值的实际API。该PInvokeStackImbalance例外来自于事实,我是在一个额外的参数添加



下面是实际的号角程序以及这样做的正确的C#语法:



号角:

  sendRequest将程序(* CString的XDATA,龙DATALEN),字节,虚拟

C#:

 函数[DllImport(NOVA_API.dll,入口点=sendRequest将)] 
私人静态外部字节sendRequest将(字符串XDATA,诠释DATALEN);

在总结,克拉里昂 * CString的 CAN转换到.NET 字符串键入dllimport的声明。



非常感谢那些谁回答。下面是我在搜索中使用一个额外的资源,我发现非常有用:的PInvoke .NET


How can I convert this Clarion procedure declaration to C#? It's part of a 3rd Party DLL written in C, which doesn't have much documentation. I have listed the prototype for the method in Clarion that is working correctly. In C#, I'm not sure what type to use to replace *CString. I tried char[] like @DanielC suggested, but it didn't work. I also found that Clarion long is 32-bit (thanks @shf301).

Clarion:

SendRequest Procedure(*CString xData,Long DataLen,Long xTimeout),Byte,Virtual

C# (what I've tried, which doesn't work):

[DllImport("3RD_PARTY_API.dll")]
private static extern long SendRequest(ref string xData, int DataLen, int xTimeout);

When I call the SendRequest method in C# I get the standard PInvokeStackImbalance was detected error from VS2010. I think it's an issue of the parameter types and not something like CharSet or EntryPoint in the DllImport declaration. I'm really just stuck on how to convert *CString to a valid C# type.

解决方案

I found the answer. I wish I still worked with the developer who wrote this code so I could yell at them. They put a wrapper around the API so that the method I listed with 3 parameters then calls the actual API without the timeout value. The PInvokeStackImbalance exception came from the fact that I was adding in an extra parameter.

Here is the actual Clarion procedure as well as the correct C# syntax for this:

Clarion:

SendRequest Procedure(*CString xData, Long DataLen), Byte, Virtual

C#:

[DllImport("NOVA_API.dll", EntryPoint = "SendRequest")]
private static extern byte SendRequest(string xData, int DataLen);

In summation, the Clarion *CString can be converted to the .NET string type in DLLImport declarations.

Many thanks to those who responded. Here is an additional resource I used in my search, which I found very usefull: pinvoke.net

这篇关于一个转换过程号角宣言C#的DllImport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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