VC++6.0でDLLの詳細ステップとその使用を記述する
2193 ワード
VC++6.0 DLL
、 DLL
1、 DLL
1.1、 FileNewProjectsWin32 Dynamic-Link Library; Project MyDll, :
1.2、 FileNewFilesC++ Source File, File :MyDll.cpp :
1.3、 FileNewFilesC/C++ Header File, File MyDll.h
1.4、 MyDll.h , :
#ifndef _MYDLL_H_
#define _MYDLL_H_
extern "C" _declspec (dllexport) int Max(int a, int b);
#endif
:
1.5、 MyDll.cpp, :
#include "MyDll.h"
int Max(int a , int b)
{
if (a >= b)
{
return a ;
}
else
{
return b ;
}
}
:
1.6、 , build ; :
、 DLL
1、 FileNewProjectsWin32 Application, Project Name UseMyDll, :
2、 UseMyDll.cpp 、UseMyDll.h ; :
3、 UseMyDll.h
#ifndef _USEMYDLL_H_
#define _USEMYDLL_H_
typedef int(*pMax) (int a, int b) ;// dll
#endif
4、 UseMyDll.CPP
#include <stdio.h>
#include <iostream.h>
#include <windows.h>
#include "UseMyDll.h"
int main(void)
{
HINSTANCE hdll;
pMax max ;
hdll = LoadLibrary("../../MyDll/Debug/MyDll.dll") ;
if (hdll == NULL){
printf("can not find dll file.") ;
return 1 ;
}
max =(pMax)GetProcAddress(hdll, "Max") ;
if (max == NULL)
{
printf("can not find the Max function.");
return 1 ;
}
int ret = max(1, 1255) ;
printf(" :%d
", ret) ;
FreeLibrary(hdll) ;
return 0 ;
}
5、 , UseMyDll ,ok。
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/UseMyDll.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
:
ProjectSettingLinkProject Options :
subsystem: windows subsystem: console;