short FindArtist(LPCTSTR artist); short AddArtist(LPCTSTR artist, LPCTSTR country, short century); short FindArtifact(LPCTSTR name, LPCTSTR artist); short AddArtifact(LPCTSTR artist, LPCTSTR name, short price);// art.c // A simple program that uses LoadLibrary and // GetProcAddress to access FindArtist function from art.dll. #include <stdio.h> #include <windows.h> //Define the function prototype typedef short (CALLBACK* FindArtistType)(LPCTSTR);void main(void) { BOOL freeResult, runTimeLinkSuccess = FALSE; HINSTANCE dllHandle = NULL; FindArtistType FindArtistPtr = NULL; //Load the dll and keep the handle to it dllHandle = LoadLibrary("art.dll"); // If the handle is valid, try to get the function address. if (NULL != dllHandle) { //Get pointer to our function using GetProcAddress: FindArtistPtr = (FindArtistType)GetProcAddress(dllHandle, "FindArtist"); // If the function address is valid, call the function. if (runTimeLinkSuccess = (NULL != FindArtistPtr)) { LPCTSTR myArtist = "Duchamp"; short retVal = FindArtistPtr(myArtist); } //Free the library: freeResult = FreeLibrary(dllHandle); } //If unable to call the DLL function, use an alternative. if(!runTimeLinkSuccess) printf("message via alternative method\n"); }
short AddArtist(LPCTSTR artist, LPCTSTR country, short century);
short FindArtifact(LPCTSTR name, LPCTSTR artist);
short AddArtifact(LPCTSTR artist, LPCTSTR name, short price);// art.c
// A simple program that uses LoadLibrary and
// GetProcAddress to access FindArtist function from art.dll.
#include <stdio.h>
#include <windows.h> //Define the function prototype
typedef short (CALLBACK* FindArtistType)(LPCTSTR);void main(void)
{
BOOL freeResult, runTimeLinkSuccess = FALSE;
HINSTANCE dllHandle = NULL;
FindArtistType FindArtistPtr = NULL; //Load the dll and keep the handle to it
dllHandle = LoadLibrary("art.dll"); // If the handle is valid, try to get the function address.
if (NULL != dllHandle)
{
//Get pointer to our function using GetProcAddress:
FindArtistPtr = (FindArtistType)GetProcAddress(dllHandle,
"FindArtist"); // If the function address is valid, call the function.
if (runTimeLinkSuccess = (NULL != FindArtistPtr))
{
LPCTSTR myArtist = "Duchamp";
short retVal = FindArtistPtr(myArtist);
} //Free the library:
freeResult = FreeLibrary(dllHandle);
} //If unable to call the DLL function, use an alternative.
if(!runTimeLinkSuccess)
printf("message via alternative method\n");
}
Win32 的 PE 文件格式和 DOS 下的 16 位 PE 文件格式是不同的