Skip to main content
gamedev.net
🔒 Locked

Function pointer mess

Started by hallgeir Jan 11, 2004 at 7:34 AM 4 replies 450+ views
Original Post
hallgeir
hallgeir
Hey. I''m having some trouble with function pointers. I''m trying to get the function pointer to a function in a .dll file, and then call it from the program (the .exe file). When I compile, the line where I call the function fails. I have commented that line below.
bool CEngine::LoadMod(const char *szModName)
{
	int (*p_fnEntry)(int (*syscall)(int, ...)) = NULL;

	if (!m_Mod.LoadModule(szModName))
	{
		return false;
	}

	p_fnEntry = (int (*)(int (*)(int, ...))) GetProcAddress(m_Mod.m_hMod,"vmEntry");
	p_fnEntry(SysCall); //this one won''t compile

	return true;
}
 
The function pointer p_fnEntry should accept another function pointer, but it doesn''t. I just get the following compile error: error C2664: ''int (int (__cdecl *)(int,...))'' : cannot convert parameter 1 from ''overloaded-function'' to ''int (__cdecl *)(int,...)'' The SysCall function that is passed to p_fnEntry is a member function of CEngine: int CEngine::SysCall(int operation, ...); Can someone tell me what could be wrong? I have checked that the function data type and the argument''s data types are correct. Could the problem have something to do with that I''m using an variable argument list on the SysCall function? I hope anyone can help. "The mistakes are all waiting to be made.
SiCrane
SiCrane
Is SysCall a static member function or an ordinary member function?
hallgeir
hallgeir
It is an ordinary (not static) member function.

"The mistakes are all waiting to be made.
targhan
targhan
then voila! there is your error
--------------------------------"I'm a half time coder, full time Britney Spears addict" Targhan
hallgeir
hallgeir
Aha.

Thanks a lot

"The mistakes are all waiting to be made.
Greatwolf
Greatwolf
you should really consider typedef''ing that sucker.

eg. something like this maybe


typedef int (*syscall)(int, ...);
typedef int (*p_fnEntryType)(syscall);
p_fnEntryType p_fnEntry = NULL;
// etc...







--{You fight like a dairy farmer!}
--{You fight like a dairy farmer!}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.