VC++6.0でDLLの詳細ステップとその使用を記述する

2193 ワード

VC++6.0   DLL        
 、	  DLL
1、	  DLL
1.1、	FileNewProjectsWin32 Dynamic-Link Library;  Project     MyDll,   :
 
1.2、	FileNewFilesC++ Source File,  File   :MyDll.cpp   :
 
1.3、	FileNewFilesC/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、	FileNewProjectsWin32 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. : ProjectSettingLinkProject Options : subsystem: windows  subsystem: console;