[問題] 無法呼叫DLL程式
開發平台(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
03/21 23:15, 1F
→
03/21 23:16, , 2F
03/21 23:16, 2F
→
03/21 23:19, , 3F
03/21 23:19, 3F
→
03/21 23:30, , 4F
03/21 23:30, 4F
→
03/21 23:32, , 5F
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
03/21 23:45, 7F
→
03/21 23:45, , 8F
03/21 23:45, 8F
→
03/21 23:47, , 9F
03/21 23:47, 9F
→
03/22 00:56, , 10F
03/22 00:56, 10F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章