[問題] 關於C#使用DllImport的問題

看板C_Sharp作者時間18年前 (2008/02/25 01:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
大家好,小弟目前碰到的問題如下: 前提: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
文章代碼(AID): #17mQMBDO (C_Sharp)