Sujay Ghosh Sujay Ghosh - 7 months ago 47
C++ Question

How do I export class functions, but not the entire class in a DLL

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
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.


I would recommend to declare an interface that will be exported and then implement it by your internal class.

class __declspec(dllexport) IClientLib {
    virtual bool Connect(char* strAccountUID,char* strAccountPWD) = 0;
    virtual void LogOut() = 0;

class CClientLib: public IClientLib {