Typedef translation

Hello,

I am following a tutorial online and so far so good (http://www.abstraction.net/ViewArticle.aspx?articleID=67). I am able to understand all of the code except for one small part which I can’t seem to make out.

At the top of the code is a typedef written as follow:

1
2
typedef IPlugin *(*PLUGIN_FACTORY)();
typedef void (*PLUGIN_CLEANUP)(IPlugin *);


And in the body of the code, it is used as so:

1
2
PLUGIN_FACTORY pFactory = (PLUGIN_FACTORY)GetProcAddress(hMod, "Create_Plugin");
PLUGIN_CLEANUP pCleanup = (PLUGIN_CLEANUP)GetProcAddres(hMod, "Release_Plugin");


Can someone please help me understand those two? If the typedef was not used, what would the second part look like?

Thank you.
Last edited on
Function pointer typedefs. http://www.newty.de/fpt/index.html
pFactory and pCleanup are pointers, and they store the result (a function pointer) returned by calling GetProcAddress().

If the typedef was not used, what would the second part look like?

Pretty ugly.

Edit:
Just for clarification:
PLUGIN_FACTORY can store the address of a function which looks like:
IPlugin functionName() {}

PLUGIN_CLEANUP:
void functionName(IPlugin *p) {}
Last edited on
typedef IPlugin *(*PLUGIN_FACTORY)();
PLUGIN_FACTORy is a pointer to function that takes no arguments and returns a pointer to IPlugin.

typedef void (*PLUGIN_CLEANUP)(IPlugin *);
PLUGIN_CLEANUP is a pointer to function that takes a pointer to IPlugin and returns nothing.

If the typedef was not used, what would the second part look like?


1
2
IPlugin *(*pFactory)() = (IPlugin *(*)())GetProcAddress(...;
void (*pCleanup)(IPlugin*) = (void(*)(IPlugin*))GetProcAddress(...;

Thank you very much for the quick replies. And thank you again Cubbi for the actual translation. Looks like I don’t understand pointers as well as I thought I did. I’m still a little bit confused, but at least I can compare and try to break it down further until it starts making sense.

Thanks again.

P.S. Thanks for the link Catfish2. It’s very helpful!
Last edited on
Topic archived. No new replies allowed.