VC++6.0 동적 라이브러리 생성 및 호출(MFC가 아닌 dll)

1756 단어 vc++
 MFC      。。。。

[cpp] view plaincopyprint?

lib.cpp  

[cpp] view plaincopyprint?

#ifndef LIB_H  

#define LIB_H  

  

//  add dll     .  

extern "C" int _declspec(dllexport)add(int x,int y);  

  

#endif  

[cpp] view plaincopyprint?

/*lib.h*/  

#ifndef LIB_H  

#define LIB_H  

  

//  add dll     .  

extern "C" int _declspec(dllexport)add(int x,int y);  

  

#endif  



     def  

[cpp] view plaincopyprint?

; lib.def :   DLL       

    

LIBRARY DllTestDef  

    

EXPORTS     

add @ 1    



 MFc      

1.    

[cpp] view plaincopyprint?

//     dll   ,  dll lib               

#include <STDIO.H>  

#pragma comment(lib,"dllTEST.lib")//..      dll   lib     。  

  

extern "C"_declspec(dllimport)add(int x,int y);//        

  

int main()  

{  

    int result=add(2,3);  

    printf("2+3=%d 
",result); return 0; } 2. [cpp] view plaincopyprint? // dll . // dll #include<stdio.h> #include<windows.h> // add . // main typedef int(*lpAddFun)(int,int);// int main() { HINSTANCE hDLL;//DLL lpAddFun addFun;// hDLL=LoadLibrary("./dllTEST.dll");// DLL , DLL hDLL. if(hDLL!=NULL) { addFun=(lpAddFun)GetProcAddress(hDLL,"add");// DLL add addFun if(addFun!=NULL) { int result=addFun(2,3);// addFun add printf("2+3= %d
",result); } FreeLibrary(hDLL);// DLL } return 0; }

좋은 웹페이지 즐겨찾기