如何导出类函数,但不是在DLL中的整个类 [英] How do I export class functions, but not the entire class in a DLL

查看:387
本文介绍了如何导出类函数,但不是在DLL中的整个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个Win32 DLL,提供下面的细节,并想为函数Connnect和LogOut创建一个CLI / C ++包装。

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

类和函数可以从DLL导出。

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;
    }

};

我想让类作为导出的函数,Connect和LogOut,使用函数set / get 。

I want to have the class as the exported functions, Connect and LogOut, uses the function set / get.

只能导出Connect和LogOut函数,而不是整个类。

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 {
 public:
    virtual bool Connect(char* strAccountUID,char* strAccountPWD) = 0;
    virtual void LogOut() = 0;
};

class CClientLib: public IClientLib {
...
};

这篇关于如何导出类函数,但不是在DLL中的整个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆