Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this syntax for defining type of functions loaded from DLL

typedef void* (*unknown)(
#ifdef __cplusplus

And then retype loads
unknown varname= (unknown)GetProcAddress(hGetProcIDDLL, "FuncName");

This gives me ability to use any function (int,int,int) (char*,int,char*) for example with no problems.

And I want to know if there is some special situation in which this can't be used or it will not work the way I explained higher?

It should work in all cases. Why not?

However, your sample looks strange due to the weird name "hGetProcIDDLL", because first parameter is the DLL module ID obtained, obtained using LoadLibrary, LoadLibraryEx, LoadPackagedLibrary, or GetModuleHandle:[^].

So, your first step should be obtaining the module handler, so you could use it as a first parameter. See the respective MSDN help pages, starting from the page referenced above.

Share this answer
Espen Harlinn 12-Mar-13 17:56pm    
Sergey Alexandrovich Kryukov 12-Mar-13 18:00pm    
Thank you, Espen.
Timotej Tomandl 13-Mar-13 15:32pm    
It is the name of class hinstances from tutorials.
Sergey Alexandrovich Kryukov 13-Mar-13 15:35pm    
Formally, it does not matter, but I'll advise you to use better names; the one from Windows API documentation is better.
Are you clear with your doubt? Will you accept the answer formally now (green button)?
Although I have never tried it, I'd say that there is a good chance that the little trick with "..." will work.

But you are depriving yourself from all the type checking that the compiler can do for you. Let's say, the function you are calling has a signature of (int, int) and instead you call it with (char*, double, double). That might result in totally unpredictable behavior of the program. The function might not even return properly. And such errors are sometimes very hard to debug.

So, I'd recommend: Do yourself a favor and define the types of the functions in your DLL properly and give the compiler a chance to detect errors in the argument sequence.
Share this answer
Sergey Alexandrovich Kryukov 13-Mar-13 15:36pm    
Good point, a 5.
nv3 13-Mar-13 16:41pm    
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900