VCでdll関数を呼び出す2つの方法
1425 ワード
、 1、 typedef int (*dll_mul)(int a,int b);2、 dll, HINSTANCE hdll=loadlibrary("c:/cppDll.dll");3、 dll dll_mul mymul=(dll_mul)GetProcAddress(hdll,"mul");4、 int sum=mymul(5,6); :
#include "stdafx.h"
#include "windows.h"
typedef int(*dll_add)(int a,int b);//
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hDll=LoadLibrary("c:/CppDll.dll");// dll
dll_add myadd=(dll_add)GetProcAddress(hDll,"mul");//
int sum=myadd(5,6);
printf("sum=%d",sum);
system("pause");
return 0;
}
、
1、 cppDll.dll , C:\Windows\System32。
2、 dll
int div(int a,int b);
3、 CppDll.lib , lib dll ,
#pragma comment(lib,"c:/CppDll.lib");
4、
int num=div(6,2);
:
#include "stdafx.h"
#include "windows.h"
int mul(int a,int b);//
#pragma comment(lib,"c:/CppDll.lib");// lib ,
int _tmain(int argc, _TCHAR* argv[])
{
int num=mul(2,3);//
printf("num=%d",num);
system("pause");
return 0;
}