7,540
社区成员
发帖
与我相关
我的任务
分享
;TestDll.cpp
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <Windows.h>
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE hfindmp3;
FARPROC fpplus;
int a,b,c;
char sfindmp3[32]="FindTheMp3.dll";
hfindmp3=LoadLibrary((LPCWSTR)sfindmp3);
if(!hfindmp3){
cout<<"Failed!"<<endl<<GetLastError()<<endl;
system("pause>nul");
return 0;
}
fpplus= GetProcAddress(hfindmp3,"plus");
do{
cin>>a>>b;
c=fpplus();
cout<<a<<'+'<<b<<'='<<c<<endl;
}while (getchar()!=27);
FreeLibrary(hfindmp3);
system("pause>nul");
return 0;
}
;FindTheMp3.cpp
#include "stdafx.h"
extern "C" int _declspec(dllexport)plus(int a,int b){
MessageBox(NULL,(LPCWSTR)"你正在调用plus函数!",(LPCWSTR)"调用成功",MB_OK);
MessageBox(NULL,(LPCWSTR)"It's so easy!",(LPCWSTR)"Hahaha......",MB_OK);
return a+b;
}
extern "C" int _declspec(dllexport)version(){
return 12345;
}
;dllmain.cpp
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
char sfindmp3[32]="FindTheMp3.dll"; hfindmp3=LoadLibrary((LPCWSTR)sfindmp3);
c=fpplus();
c=fpplus(a,b);
char sfindmp3[32]="FindTheMp3.dll";
hfindmp3=LoadLibrary((LPCWSTR)sfindmp3);