[問題] 無法呼叫DLL程式

看板C_and_CPP (C/C++)作者 (我是金順啦)時間15年前 (2011/03/21 23:06), 編輯推噓1(109)
留言10則, 5人參與, 最新討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) DEV C++ 問題(Question): 無法呼叫 DLL 程式 我只寫了超簡單的 DLL,卻一直無法呼叫成功,麻煩大家幫我看看 預期結果: 寫入dll.txt文字 感謝之意: 如果可以幫我解決,我願送你我所有p幣的一半 程式碼:(附連結) 檔頭dll.h http://codepad.org/NYA2xYZ1 #include <iostream> #include <string> #ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ #ifdef __cplusplus using namespace std; extern "C" { DLLIMPORT void writefile_jacky(string write_order, string write_price); } #endif /* _DLL_H_ */ dll主程式:dllmain.cpp http://codepad.org/qT2XWrhU #include <iostream> #include <fstream> #include <string> #include <stdio.h> #include <stdlib.h> using namespace std; void writefile_jacky(string write_order, string write_price) { ofstream myfile; myfile.open ("dll.txt"); myfile << "write"; myfile.close(); } 最後的主程式:main.cpp http://codepad.org/so6Xerwf #include <cstdlib> #include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include "windows.h" using namespace std; int main() { HMODULE hInst; typedef int (*WRITEFILE_JACKY)(string,string); WRITEFILE_JACKY writefile_jacky; hInst = LoadLibrary("jacky.dll"); writefile_jacky=(WRITEFILE_JACKY) GetProcAddress(hInst,"writefile_jacky"); writefile_jacky("main","success"); FreeLibrary(hInst); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.136.198.52

03/21 23:15, , 1F
GetProcAddress(hInst,"_writefile_jacky");
03/21 23:15, 1F

03/21 23:16, , 2F
色碼沒打好 XDD
03/21 23:16, 2F

03/21 23:19, , 3F
給樓樓上,我多加了底線,還是沒用哩,麻煩再看一下
03/21 23:19, 3F

03/21 23:30, , 4F
給樓樓上,色碼超難用,跟C code一樣難寫 XXD
03/21 23:30, 4F

03/21 23:32, , 5F
其實可以用置底文的網址貼code
03/21 23:32, 5F
※ 編輯: ncuoo 來自: 114.136.198.52 (03/21 23:42)

03/21 23:40, , 6F
就你貼的這些,這樣可以編譯的了?
03/21 23:40, 6F

03/21 23:45, , 7F
給樓上,DEV C++可以compiler呀
03/21 23:45, 7F

03/21 23:45, , 8F
如果可以幫我解決,我願送你我所有p幣的一半
03/21 23:45, 8F

03/21 23:47, , 9F
約4500元p幣
03/21 23:47, 9F

03/22 00:56, , 10F
DLL傳上來看看
03/22 00:56, 10F
文章代碼(AID): #1DXsbdav (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1DXsbdav (C_and_CPP)