Need help with exporting functions in a dll
I have a dll that I want to load at run time. The problem is I don't know what functions it exports. Is there a way, at run time, I could load the dll, find out what functions it exports, and then call them? Thanks you,
-Corellian
[244 byte] By [
Corellian] at [2007-11-17 11:49:09]

# 1 Re: Need help with exporting functions in a dll
Hi ,
u can use dumpbin.exe file which is available in VC98\bin directory to see the list of exported functions in the dll.
Rate if it helped u.
VCVCVC
VCVCVC at 2007-11-10 8:06:48 >

# 2 Re: Need help with exporting functions in a dll
Try to use LoadLibrary() and GetProcAddress() functions. Here is an example that hide your aplication ID. When you press Ctrl-Alt-Del your app. won't be listed there:
typedef DWORD (WINAPI *HideCAD)(DWORD,DWORD);
void HideAplication(int state){
HMODULE kernel32dll;
HideCAD ourFunction;
kernel32dll=LoadLibrary("kernel32.dll");
ourFunction=(HideCAD)GetProcAddress(kernel32dll,"RegisterServiceProcess"); //the RegisterServiceProcess() function does our goal :))
if(state)
ourFunction(0,1);
else
ourFunction(0,0);
FreeLibrary(kernel32dll);
}
# 3 Re: Need help with exporting functions in a dll
Hi!
U can use Dynamic Linking of the DLL i.e. u load the DLL at run BUT u hav to know the paramters of the functions and function names. U can get the exported function name from Dumpbin utlilty but u must know the function parametes. Here is an example.
int (*funptr) (void); // u hav to know the type of function i.e. the parameters and return type there is no utlility that can get u the parameters of the functions.
HINSTANCE hDll = LoadLibrary("mfc42.dll");
if(hDll != NULL)
AfxMessageBox("Got the Handle");
else
AfxMessageBox("No Handle");
funptr = (int (*) (void))GetProcAddress((HMODULE)hDll, "DllCanUnloadNow"); // if ur uncertain u can check the pointer to the function that u get back if its not null then u hav a valid pointer u can call the function then.
if(funptr != NULL)
funptr();
else
AfxMessageBox("Dont call the Function otherwise u will get into trouble :(");
Regards,
Rate it, if it Helps.
Regards,
Usman.
--
Good judgment is gained from experience. Experience is gained from bad judgment.
# 4 Re: Need help with exporting functions in a dll
Hi!
U can use Dynamic Linking of the DLL i.e. u load the DLL at run BUT u hav to know the paramters of the functions and function names. U can get the exported function name from Dumpbin utlilty but u must know the function parametes. Here is an example.
int (*funptr) (void); // u hav to know the type of function i.e. the parameters and return type there is no utlility that can get u the parameters of the functions.
HINSTANCE hDll = LoadLibrary("mfc42.dll");
if(hDll != NULL)
AfxMessageBox("Got the Handle");
else
AfxMessageBox("No Handle");
funptr = (int (*) (void))GetProcAddress((HMODULE)hDll, "DllCanUnloadNow"); // if ur uncertain u can check the pointer to the function that u get back if its not null then u hav a valid pointer u can call the function then.
if(funptr != NULL)
funptr();
else
AfxMessageBox("Dont call the Function otherwise u will get into trouble :(");
Regards,
Rate it, if it Helps.
Regards,
Usman.
--
Good judgment is gained from experience. Experience is gained from bad judgment.
# 5 Re: Need help with exporting functions in a dll
Hi!
U can use Dynamic Linking of the DLL i.e. u load the DLL at run BUT u hav to know the paramters of the functions and function names. U can get the exported function name from Dumpbin utlilty but u must know the function parametes. Here is an example.
int (*funptr) (void); // u hav to know the type of function i.e. the parameters and return type there is no utlility that can get u the parameters of the functions.
HINSTANCE hDll = LoadLibrary("mfc42.dll");
if(hDll != NULL)
AfxMessageBox("Got the Handle");
else
AfxMessageBox("No Handle");
funptr = (int (*) (void))GetProcAddress((HMODULE)hDll, "DllCanUnloadNow"); // if ur uncertain u can check the pointer to the function that u get back if its not null then u hav a valid pointer u can call the function then.
if(funptr != NULL)
funptr();
else
AfxMessageBox("Dont call the Function otherwise u will get into trouble :(");
Regards,
Rate it, if it Helps.
Regards,
Usman.
--
Good judgment is gained from experience. Experience is gained from bad judgment.
