Essentially, I’d like to be able to do something like this:
//assume myFunction is defined and takes one argument that is an int
char * functionName = "myFunction";
int arg = 5;
__asm{
push a
call functionName
}
Basically I want to call a function whose name is stored in a string. What would be the proper syntax for doing this?
Edit:
We are talking about x86 assembly
You can’t, at least not directly.
call takes an address as a parameter. Even though you write “call functionName”, the linker replaces functionname with the actual address of the function. You’d need to first map that string to its address. In general, C and C++ don’t support any sort of runtime metadata about function name mappings that would allow for this. If the function is exported from a DLL, you can use GetProcAddress to find its address.
If the list of functions is static, you can create the mapping ahead of time yourself.
Something like:
Some notes:
I believe the standard says that a function pointer may be larger than a PVOID. This should work on Windows x86/x64 platforms.
You didn’t say what calling convention you were using – this code presumes stdcall.
This is a very, very odd thing to want to accomplish – what problem are you trying to solve?