看板 C_and_CPP 關於我們 聯絡資訊
小弟透過C#去使用第三方(C/C++)的DLL時,遇到如下的例外訊息 攔截到 System.AccessViolationException Message="嘗試讀取或寫入受保護的記憶體。這通常表示其他記憶體已損毀。" 本以為是在包DLL時參數型態給定錯誤, 但其實該DLL的方法確實有成功執行(透過該DLL方法寫入的特定log檔得知) 不知道大家可以看一下我寫的程式是否有問題~~thx 目前比較懷疑回傳的型態,我用String去接,是否有誤... ----C#程式片段---------- [DllImport("dllbndclir.dll", SetLastError = true)] private unsafe static extern String msgCliFixConn( String senderID, String targetID, String basePath, String host, int port, int hbt, String profile, int errorCode, String Encode); string msgCliHdl = msgCliConn( "9700001", "9720001", "./Log", "192.168.11.11", 11122, 6, "setting.ini", 0, null); ---廠商提供的DLL說明(片段)------- .... typedef char *msgCliHdl_t; ... /** * Input * (略) * return * return NULL if failure -- msgCliHdl is not allocated. * Othereise, return allocated msgCliHdl. * */ msgCliHdl_t CallStack msgCliConn(char *senderID, char *targetID, char *basePath, char *host, int port, int hbt, char *profile, int errorCode, Char *Encode); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.217.32.71
Killercat:maa, c#板在c_sharp... 不過我記得managed code要invoke 02/05 23:46
Killercat:unmanaged的dll好像要額外多做一個步驟 我查一下 02/05 23:47
Killercat:找到了 http://tinyurl.com/aga5kn 這也是我個人不太偏 02/05 23:49
Killercat:好使用managed code的一個滿重要的原因 :/ 02/05 23:49
iamkjs:抱歉,我想說C#呼叫的是C/C++的DLL,應該有關聯吧...XD 02/06 00:27
iamkjs:K大,你提供的網址就是我現在的作法,但是仍有問題... 02/06 00:28