C++ DLL调用

#include <windows.h> 
#include <stdio.h> 
typedef int (__cdecl *MYPROC)(int,int);

VOID main(VOID) 
{ 
    HINSTANCE hinstLib; 
    MYPROC ProcAdd; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
    // DLLNAME,DLL文件名 
    hinstLib = LoadLibrary(TEXT("DLLNAME")); 
    // If the handle is valid, try to get the function address.
    if (hinstLib != NULL) 
    { 
		// DLL文件功能函数,FUNC        
		ProcAdd = (MYPROC) GetProcAddress(hinstLib, "FUNC"); 
        // If the function address is valid, call the function.
        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
			printf("%d",(ProcAdd)(1,2));
        }
        // Free the DLL module.
        fFreeResult = FreeLibrary(hinstLib); 
    } 
    // If unable to call the DLL function, use an alternative.
    if (! fRunTimeLinkSuccess) 
        printf("Message printed from executable\n"); 

	system("pause");
}

DLL.CPP

#include "DLL.h"

int add(int x,int y)
{
return x+y;
}

DLL.H

extern "C" __declspec(dllexport)int add(int,int);


 




   

你可能感兴趣的:(C++,function,null,System,dll,include)