
07-06-2008, 20:56
|
|
|
|
חבר מתאריך: 07.06.08
הודעות: 9
|
|
יש לך שתי אופציות.
או לטעון את ה-DLL בתחילת התוכנית, או במהלכה. הדרך הכי פשוטה (אבל יש איתה בעיות) היא תוך כדי ריצה. הנה קוד דוגמה:
קוד:
#include <stdio.h>
#include <windows.h>
typedef short (_stdcall *Inp32)(short); //The prototype of the function you wish to call
int main(int argc, char* argv[])
{
char *lib_name = "inpout32.dll"; // The Name of the dll you want to load
// You should put the dll in the library of your application
char *in_function_name = "Inp32"; // The name of the function you want to call
HINSTANCE hDll;
Inp32 _Inp32; // A pointer to the funtion
hDll = LoadLibrary(lib_name); // Load the dll you wish
if (hDll == NULL) { // Check if loaded correctly
printf("Error Loading Library: %d", GetLastError());
return 1;
}
_Inp32 = (Inp32)GetProcAddress(hDll, in_function_name); // Obtain the function address
if (_Inp32 == NULL) { // Check for errors
printf("Error Getting Proc Address: %d", GetLastError());
return 1;
}
printf("Input: %d", _Inp32(0x378)); //Call the function
FreeLibrary(hDll); // Unload the library
return 0;
}
עלמנת לטעון עוד פונקציות, קרא את הקוד שבתוך הזיפ.
בהצלחה!
|