作者local9433 ()
看板C_Sharp
标题[问题] 关於C#使用DllImport的问题
时间Mon Feb 25 01:12:42 2008
大家好,小弟目前碰到的问题如下:
前提:1.要写一个在PDA读取RFID tag的功能
2.厂商有给RFIDAPI.dll以及Dll档里function的说明书
问题开始:
我想要呼叫Dll里面的SelectTag函式
以下是厂商说明文件对SelectTag函式说明的内容:
----------------------------------------------------------------------------------------
Function Description:
Reader will automatically select one available tag from field and then
read tag ID
Function call:
long SelectTag(int iTagProtocol,LPTSTR &lpBuf)
Parameter(Input)
iTagProtocol : refer to TagProtocol Property
Parameter(output)
lpBuf : tag id string
Return code:
Refer to Error Code Property
Example code:
LPTSTR strTAG;
int protocol = 6;
long ErrCode = SelectTag(protocol,strTAG);
if (ErrCode == 0) {
}
---------------------------------------------------------------------------------------------
以下是我叫用函式的程式码片段:
[DllImport("RFIDAPI.dll", EntryPoint = "?SelectTag@@YAJHAAPAG@Z")]
public static extern Int32 SelectTag(int iTagProtocol,
[MarshalAs(UnmanagedType.LPTStr)] ref String lpBuf);
String OutputTagID = "";
int protocol = 6;
Int32 ErrCode = SelectTag(protocol,ref OutputTagID);
----------------------------------------------------------------------------------------------
执行结果出来还是在呼叫SelectTag的地方
Int32 ErrCode = SelectTag(protocol, ref OutputTagID);
跳出NotSupportedException
我在想是在叫用函式时,是不是第二个参数封送不对?
看厂商的说明第二个参数是用来接收Output结果。该怎麽写才会正确呢?
谢谢大家的帮忙
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.224.223.41