Reputation: 59
I have a program where I'm dynamically loading a dll and using a 'factory' function to get a class instance. (I actually pulled this from a post I read somewhere on the Net and just blindly used it.) To do this, I have a code snippet like the following:
typedef IHermes* (*pHermesFactory)();
pHermesFactory pHermes = (pHermesFactory)GetProcAddress(hInstance, "HermesFactory");
My question is - what does that last line become after the typedef 'replacement'? When I tried to figure it out by hand I came up with:
IHermes* (*pHermes)() = (IHermes* (*GetProcAddress(hInstance, "HermesFactory"))();
Does anyone know if this is right? I really don't NEED to know, but I'd like to understand typedef's a bit better.
Upvotes: 1
Views: 55
Reputation: 490138
Without the typedef, you need to specify the pointer to function
both as the type of the variable and as the cast, so you'd end up with something like this (I've separated into a definition and assignment in the hope of slightly improved clarity).
IHermes* (*pHermes)();
pHermes = (IHermes*(*)())GetProcAddress(hInstance, "HermesFactory");
Those can be combined into one horrible mess though:
IHermes* (*pHermes)() = (IHermes*(*)())GetProcAddress(hInstance, "HermesFactory");
Upvotes: 4