I have developed a Win32 DLL, providing the details below, and want to create a CLI/C++ wrapper for the functions Connnect and LogOut.
I know that entire classes and functions can be exported from a DLL.
class CClientLib
{
public:
CClientLib (void);
// TODO: add your methods here.
__declspec(dllexport) bool Connect(char* strAccountUID,char* strAccountPWD);
__declspec(dllexport) void LogOut();
private :
Account::Ref UserAccount ;
void set_ActiveAccount(Account::Ref act)
{
// Set the active account
}
Account::Ref get_ActiveAccount()
{
return UserAccount;
}
};
I want to have the class as the exported functions, Connect and LogOut, uses the function set / get.
Is it possible only to export the functions Connect and LogOut, and not the entire class.
Use __declspec(dllexport) to export the function or method. You can export an entire C++ class by placing the __declspec(dllexport) before the class name, or you can export a single method by placing __declspec(dllexport) before the method name. Make class methods static and public.
__declspec(dllexport) adds the export directive to the object file so you do not need to use a . def file. This convenience is most apparent when trying to export decorated C++ function names.
dllexport of a C++ function will expose the function with C++ name mangling. To disable name mangling either use a . def file (EXPORTS keyword) or declare the function as extern “C”.
I would recommend to declare an interface that will be exported and then implement it by your internal class.
class __declspec(dllexport) IClientLib {
public:
virtual bool Connect(char* strAccountUID,char* strAccountPWD) = 0;
virtual void LogOut() = 0;
};
class CClientLib: public IClientLib {
...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With