Sign in to follow this  

Function pointer

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this