通过c ++界面导出整个类 [英] Export entire class through c++ interface

查看:109
本文介绍了通过c ++界面导出整个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我将重写问题。
1.是否足够做

  class __declspec(dllexport)CXyz {
public:
int Food(){printf(Food\\\
);}
};

这样可以在exe中使用类:

  #includeCXyz.h
CXyz obj;
obj.Food();

2。当我做CXyz x(成员和方法代码分配)时,会发生什么,我的意思是它分配一个线性结构的大小(aprox。成员大小+方法的函数指针),方法代码是在.code该程序?当我做CXyz * pX时会发生什么?

解决方案


  1. 不够。在客户端CXyz必须声明为__declspec(dllimport)。这通常通过条件编译完成,当一些宏在Dll中扩展为__declspec(dllexport),并在客户机项目中扩展为__declspec(dllimport)时。使用VS应用程序向导创建示例Dll,在其中一个向导步骤中检查导出符号,看看它是如何完成的。当然,客户端项目应该与服务器.lib文件链接,并且服务器Dll应该在运行时可用。


  2. 分配。装配级别上的类方法是具有隐藏的this参数的全局函数。



Ok, I'll rewrite the question(s). 1. Is it enough to do

class __declspec(dllexport) CXyz {
public:
int Food() {printf("Food\n");}
};

So that the class could be used like this in the exe:

#include "CXyz.h"
CXyz obj;
obj.Food();

2. What happens when I do CXyz x ( member & methods code allocation), I mean does it allocate a linear structure with the size of (aprox. members size + function pointers for the methods) and method code is in the section .code of the program? What happens when I do CXyz *pX ?

解决方案

  1. Not enough. On the client side CXyz must be declared as __declspec(dllimport). This is usually done by conditional compilation, when some macro is expanded to __declspec(dllexport) in Dll, and to __declspec(dllimport) in a client project. Create sample Dll using VS Application Wizard, check "Export symbols" on one of the Wizard steps, and see, how it is done. And of course, client project should be linked with server .lib file, and server Dll should be available at runtime.

  2. Only class members (and possibly vtable) are allocated. Class methods on Assembly level are global functions with hidden "this" parameter.

这篇关于通过c ++界面导出整个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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