Re: [問題] 無法呼叫DLL程式

看板C_and_CPP (C/C++)作者 (我要加入劍道社!)時間15年前 (2011/03/22 00:48), 編輯推噓4(403)
留言7則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《ncuoo (我是金順啦)》之銘言: : 檔頭dll.h http://codepad.org/NYA2xYZ1 : #include <iostream> : #include <string> : #ifndef _DLL_H_ : #define _DLL_H_ 1. 任何 identifier 都不要用底線+大寫開頭,那是留給 standard library 用的 2. include guard 應該寫在檔案最前面 (在 #include 之前) : #if BUILDING_DLL : # define DLLIMPORT __declspec (dllexport) : #else /* Not BUILDING_DLL */ : # define DLLIMPORT __declspec (dllimport) : #endif /* Not BUILDING_DLL */ : #ifdef __cplusplus : using namespace std; header file 不要用 using namespace : extern "C" { : DLLIMPORT void writefile_jacky(string write_order, string write_price); : } writefile_jacky 是使用 C convention 的函式 可是它的參數會接 C++ 物件 你不覺得哪裡怪怪的? 這樣做不是不行啦 但是既然你的 DLL 是要拿來 dynamic load 那傳遞 C++ 物件之前可能要確保一下 client 和你使用相同版本的 compiler : #endif /* _DLL_H_ */ 少了一個 #endif 你忘了 __cplusplus 嗎? : dll主程式:dllmain.cpp http://codepad.org/qT2XWrhU : #include <iostream> : #include <fstream> : #include <string> : #include <stdio.h> : #include <stdlib.h> 少了 #include "dll.h" 沒有它的話 compiler 就不知道你的 writefile_jacky 是要拿來 export 的 所以 LoadLibrary 之後會找不到那個 symbol (本來覺得很奇怪 你少了一個 #endif 應該會有 compile error 才對) (結果你是根本沒 include!) [以下略] -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.168.83.71

03/22 01:01, , 1F
4.5k 到手了嗎?
03/22 01:01, 1F

03/22 10:50, , 2F
還沒耶...可能是因為我只用VC測試 XD
03/22 10:50, 2F

03/22 12:24, , 3F
果然跑出一大堆 compiler error,只是現在上班中~晚上來解
03/22 12:24, 3F

03/22 12:26, , 4F
晚上再來解,樓上請等我的 4.5k
03/22 12:26, 4F

03/23 20:09, , 5F
成功了哩,大感謝,請看看帳戶裡有沒有多4.5k
03/23 20:09, 5F

03/23 20:38, , 6F
XDD
03/23 20:38, 6F

03/24 10:57, , 7F
收到了耶!謝謝 (羞
03/24 10:57, 7F
文章代碼(AID): #1DXu55y8 (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1DXu55y8 (C_and_CPP)