I'm writing unit tests for a dll just developed. To make the test program more flexible (the environment is composed by many other dependencies), I'm experimenting dll loading at run-time using LoadLibrary and GetProcAddress Win32 API, so that each path could be easily configurable.
The approach seems to work good but I don't like the fact that I have to declare function pointers for all the functions I have to test although I have the header file with the prototypes. I would like to know if I can exploit this header file to avoid re-declaring all function in my test program as function pointers or if at least there is a way better than mine.
At this time if I want to load at run time a mylib.dll function: int fun1(int a, int b), I make something like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* I would like to avoid this,and to exploit the original myfun.h without modifing it */
typedefint (*pfun1)(int a, int b);
static pfun1 fun1;
int main(){
int res;
HINSTANCE hMylib = LoadLibrary("mylib.dll");
fun1 = GetProcAddress(hMylib, "fun1");
res = fun1(3,3);
}