#include <iostream>
#include <Windows.h> //新版本里面,要包含下面的头文件就必须要Windows.h
#include <libloaderapi.h> //需要用到下文中的LoadLibrary()
#include <fstream>
#include <iostream>
using namespace std;
//导入动态库
//使用了unicode字符集,LoadLibrary 是LoadLibraryW(LPCWSTR lpLibFileName),需要注意参数类型转换
//AfxLoadLibrary("FightDetDll.dll")
//LoadLibrary("FightDetDll.dll")
HMODULE DllHolder = LoadLibraryA("F:\\mycode\\SiInterface.dll");
typedef int(_stdcall* SiMessage)(char*, char*);
int main() {
SiMessage sendmsg = (SiMessage)GetProcAddress(DllHolder, "SiMessage");
GetProcAddress(DllHolder, "SiMessage");
char x[100];
std::string str = "Hello";
char* cstr = (char*)str.c_str();
if (sendmsg != NULL)
{
sendmsg(cstr, x);
}
FreeLibrary(DllHolder);
std::ofstream file("example.txt", std::ios::app);
if (file.is_open()) {
file << "This is an appended line." << std::endl;
file << x << std::endl;
file.close();
}
else {
std::cout << "Unable to open file";
}
return 0;
}
#include <Windows.h> //新版本里面,要包含下面的头文件就必须要Windows.h
#include <libloaderapi.h> //需要用到下文中的LoadLibrary()
#include <fstream>
#include <iostream>
using namespace std;
//导入动态库
//使用了unicode字符集,LoadLibrary 是LoadLibraryW(LPCWSTR lpLibFileName),需要注意参数类型转换
//AfxLoadLibrary("FightDetDll.dll")
//LoadLibrary("FightDetDll.dll")
HMODULE DllHolder = LoadLibraryA("F:\\mycode\\SiInterface.dll");
typedef int(_stdcall* SiMessage)(char*, char*);
int main() {
SiMessage sendmsg = (SiMessage)GetProcAddress(DllHolder, "SiMessage");
GetProcAddress(DllHolder, "SiMessage");
char x[100];
std::string str = "Hello";
char* cstr = (char*)str.c_str();
if (sendmsg != NULL)
{
sendmsg(cstr, x);
}
FreeLibrary(DllHolder);
std::ofstream file("example.txt", std::ios::app);
if (file.is_open()) {
file << "This is an appended line." << std::endl;
file << x << std::endl;
file.close();
}
else {
std::cout << "Unable to open file";
}
return 0;
}