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.
Consider what you are asking about... both
Connect
andLogout
are non-static member functions, which means that you need to call them on an instance of the type:intense.Connect()
. Now, if you do not export the class itself, you will not be able to create theinstance
, and whetherConnect
andLogout
are exported or not makes no difference, they would be unusable.An alternative would be not to export any of them, and provide exported free functions with the same functionality that apply to some instance of your class that is not visible outside of your DLL. Alternatively offer a third function that creates a handle into your library, where handle could be an opaque (
void*
) pointer to a dynamically allocated instance of your type, and then pass the handle as an extra argument to your free function versions ofConnect
andLogout
. You will also need to add a fourth function to release that object.You can make it by simply creating two functions wich call the desired class methods end export them. i.e.
But I don't understand why you need this, since it's enough to mark the methods you don't want to be accessible with the "private" modifier (as done in your example).
I would recommend to declare an interface that will be exported and then implement it by your internal class.