C# 调用 C写的DLL 问题
来源:百度知道 编辑:UC知道 时间:2024/06/01 13:52:32
函数原型:#define COMMEXPORT extern "C" __declspec(dllexport)
COMMEXPORT BOOL FAR RegisterOnZXTcp(HWND hWnd, WORD curPNo);
参 数:hWnd ------- WINNTTCP窗口句柄
curPNo ------- 接口机的PNO
输 出:BOOL值,注册是否成功
我要在 C# 中调用
以下写法是否有问题
[DllImport("COMM.dll", EntryPoint = "RegisterOnZXTcp", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern bool RegisterOnZXTcp(int HWND, int curPNo);
在 C# 下我调用 RegisterOnZXTcp函数,无论我传入什么值,反回都是TRUE,为什么?
-
由于问题比较少见,怕没人能回答,如果答案能解决问题,加分50,避免无答案而浪费 ^_^。
using System.Runtime.InteropServices;
这行我加过了的,还是感谢 ^_^
using System.Runtime.InteropServices;
在 C# 中的调用写的有问题 参数类型弄错了
[DllImport("COMM.dll", EntryPoint = "RegisterOnZXTcp", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
//参 数:hWnd ------- WINNTTCP窗口句柄 C#中的句柄类型为 IntPtr
//curPNo ------- 接口机的PNO 可以设为string 类型
//输 出:BOOL值,注册是否成功
public static extern bool RegisterOnZXTcp(IntPtr HWND, string curPNo);
你的意思是用C#调用C写的dll对吧?
以前弄过,好久了
好像是在使用dll的时候头文件中必须加上
using System.Runtime.InteropServices;
你试试看吧
using System.Runtime.InteropServices;
在 C# 中的调用写的有问题 参数类型弄错了
[DllImport("COMM.dll", EntryPoint = "RegisterOnZXTcp", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
//参 数:hWnd ------- WINNTTCP窗口句柄 C#中的句柄类型为 IntPtr
//curPNo ------- 接口机的PNO 可以设为string 类型
//输 出:BOOL值,注册是否成功
public static extern bool RegisterOnZXTcp(IntPtr HWND, string curPNo);
__declspec(