In C it is rather trivial, since it only require creating pointer to function, so I will use inline assembler as a prove of concept:

#include <windows.h>

int main() {
    HMODULE hModule = GetModuleHandle("kernel32.dll");
    void * pFunc = GetProcAddress(hModule, "Beep");

	__asm {
	MOV EAX, 1000
	PUSH EAX
	MOV EAX, 750
	PUSH EAX
	CALL pFunc
	}

	return 0;
}

GetModuleHandle and GetProcAddress names are self-explanatory (more details on MSDN).
What’s worth mentioning is that stack on x86/64 is LIFO and in case of BOOL WINAPI Beep(DWORD dwFreq, DWORD dwDuration), parameter dwDuration should be pushed before dwFreq.

Leave a Reply

Your email address will not be published. Required fields are marked *