Skip to main content
GameDev.net gamedev.net
🔒 Locked

Function pointer

Started by ApolloCay Oct 10, 2004 at 3:07 AM 1 replies 600+ views
Original Post
ApolloCay
ApolloCay
I've run across some code like below:

// Located in .h file
HRESULT CreateDevice(CInterface **pInterface, HINSTANCE dll);
typedef HRESULT (*RENDER) (CInterface **pInterface, HINSTANCE dll) // functions pointer to above function

// Located in .cpp file
HRESULT hr;
RENDER RenderDevice = 0;
RenderDevice = (RENDER) GetProcAddress(m_DLL, "CreateDevice");

hr = RenderDevice(pDevice, m_DLL);


It's only pieces of the actual source. What I'm confused on is how RenderDevice is an object of RENDER (the function pointer) and then cast on the next line. Can someone explain why this works or point to a site that explains it?
Oluseyi
Oluseyi
RenderDevice is a pointer. It's type is RENDER, which is a typedef for a pointer to a function that returns HRESULT and takes CInterface ** and HINSTANCE parameters. It is being assigned the address retrieved by GetProcAddress, which returns LPVOID. In short, the cast is to resolve the types and eliminate a compiler warning or error about implicit casting.
silvermace
silvermace
how experienced are you with C++ and programming in general?
if you give us an idea of how much you already know, we can probably give you a much much more comprehensive answer.

cheers,
danu

Topic Locked

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

Sign in to reply to this topic.