How to export class functions, but not the whole class in DLL

I developed the Win32 DLL by providing the details below and want to create a CLI / C ++ wrapper for the Connnect and LogOut functions.

I know that whole 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 the class as exported functions, Connect and LogOut, to use the set / get function.

Is it possible to export only Connect and LogOut functions, and not the whole class.

+3
source share
3 answers

I would recommend declaring an interface to be exported, and then implement it according to your inner class.

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

class CClientLib: public IClientLib {
...
};
+9
source

, ... Connect Logout - -, , : intense.Connect(). , , instance Connect Logout , .

- , , , DLL. , , (void*) , Connect Logout. .

0

You can do this by simply creating two functions that call the necessary methods of the class to export them. i.e.

CCLientLib g_clientLib;

__declspec(dllexport) void CClientLib_LogOut()
{
    g_clientLib.LogOut();
}

But I don’t understand why you need this, since it’s enough to note the methods that you do not want to receive using the “private” modifier (as is done in your example).

0
source

All Articles