Reputation: 11
/* This is part of code copied from http://www.cplusplus.com/articles/48TbqMoL/. */
//The functions declared in *.dll source code.
DLLAPI std::unique_ptr<Base> getObj(void);
DLLAPI std::string getName(void);
//The code to import functions from loaded library( which is named temp). What is "_Z6","v" in "_Z6getObjv"?
typedef std::unique_ptr<Base> (__cdecl *ObjProc)(void);
typedef std::string (__cdecl *NameProc)(void);
ObjProc objFunc = (ObjProc)GetProcAddress(temp, "_Z6getObjv");
NameProc nameFunc = (NameProc)GetProcAddress(temp, "_Z7getNamev");
Upvotes: 1
Views: 139
Reputation: 101756
How the exported functions are named is compiler specific, see name mangling for more information. (_Z*
is probably GCC v3+)
If you are building some sort of plug-in system you should have a public ABI with fixed function names. You can use a .DEF file to control the exported names.
With the Microsoft C/C++ toolchain you can also export a unmangled name with EXTERN_C __declspec(dllexport) int __cdecl MyFunc(long parm1) { return 0; }
Use Dependency Walker to see what your functions are actually exported as.
Upvotes: 3