根据MSDN:
- //File:RUNTIME.C
- //AsimpleprogramthatusesLoadLibraryand
- //GetProcAddresstoaccessmyPutsfromMYPUTS.DLL.
- #include<stdio.h>
- #include<windows.h>
- typedefVOID(*MYPROC)(LPTSTR);
- VOIDmain(VOID)
- {
- HINSTANCEhinstLib;
- MYPROCProcAdd;
- BOOLfFreeResult,fRunTimeLinkSuccess=FALSE;
- //GetahandletotheDLLmodule.
- hinstLib=LoadLibrary("myputs");
- //Ifthehandleisvalid,trytogetthefunctionaddress.
- if(hinstLib!=NULL)
- {
- ProcAdd=(MYPROC)GetProcAddress(hinstLib,"myPuts");
- //Ifthefunctionaddressisvalid,callthefunction.
- if(fRunTimeLinkSuccess=(ProcAdd!=NULL))
- (ProcAdd)("messageviaDLLfunction/n");
- //FreetheDLLmodule.
- fFreeResult=FreeLibrary(hinstLib);
- }
- //IfunabletocalltheDLLfunction,useanalternative.
- if(!fRunTimeLinkSuccess)
- printf("messageviaalternativemethod/n");
- }
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
本文介绍了一个简单的程序示例,该程序使用LoadLibrary和GetProcAddress函数来动态加载和调用DLL中的函数myPuts。通过这个例子,读者可以了解如何在运行时链接DLL中的函数。
5495

被折叠的 条评论
为什么被折叠?



