I have a function pointer in a dll file (in implementation, not header). How can I call the function pointed to by this pointer in the exe source code?
Asked
Active
Viewed 2,160 times
1
-
If it is declared with global scope then you can just export the variable directly. That's pretty open to abuse though. – David Heffernan Oct 14 '11 at 08:00
-
how to abuse it, in what way? – Hayri Uğur Koltuk Oct 15 '11 at 19:28
-
It's just not very well encapsulated. But it is perfectly normal and common to export variables from DLLs. And a function pointer is just a variable. – David Heffernan Oct 15 '11 at 19:29
1 Answers
2
you can export a function returning the pointer. Header:
typedef void ( *MyPtr ) ();
__declspec( dllexport ) MyPtr GetMyPtr();
Source:
MyPtr GetMyPtr()
{
//retunr the function pointer here
}

stijn
- 34,664
- 13
- 111
- 163
-
1Or better and more flexible, fill in a struct of function pointers passed by pointer. – Zan Lynx Oct 14 '11 at 07:23