Dynamic Dll Function Calling - Part 2

Last edited on
I don't get the point ( I haven't checked out the link though)
Do do it like that. Cast func to the type you expect it to be, then call it like any other function.

e.g.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h>

int main()
{
	if (HINSTANCE Dll = LoadLibrary("user32.dll"))
	{
		int (*Func)(HWND, LPCTSTR, LPCTSTR, UINT) =
			(int(*)(HWND, LPCTSTR, LPCTSTR, UINT))GetProcAddress(Dll, "MessageBoxA");

		Func(0, "Question?", "Title!", MB_ICONEXCLAMATION | MB_YESNO);

		FreeLibrary(Dll);
	}

	return 0;
}
Last edited on
You really seem to have missed the point, its about calling ANY function from ANY DLL during runtime

meaning if id input some information about what function to call in what dll and what parameters it has, that the program is able to call it

Ofcourse you can cast it to the type you expect it to be, but thats not dynamic, you can only call functions with those exact parameter types, with this, it doesnt matter, you can call whatever you like

you should just check out the example files
You're right, I did miss the point. Presumably you want to drive this from some scripted thing. After all that's what VB does.

But in order to call any function in any DLL, you still need to know the parameters, their types and the calling convention to be used (prototype), and you'll still need some system to save the user from himself (type enforcement).
Topic archived. No new replies allowed.