根据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" />