在C ++ dll中需要一个变量 [英] Need a variable in C++ dll

查看:77
本文介绍了在C ++ dll中需要一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <windows.h>
// This class is exported from the DLL1.dll
class DLL1_API CDLL1
{
public:
    BSTR test;
    CDLL1();
    int GetCpuSpeed();
};




Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\documents and settings\hz0ss1\my documents\downloads\dll1\dll1.h 32 1 DLL1




Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\documents and settings\hz0ss1\my documents\downloads\dll1\dll1.h 32 1 DLL1

推荐答案

http://edais. mvps.org/Tutorials/CDLL/index.html [ ^ ]


应在C ++中使用:

类名称:testClasss

代码:

//测试对象ID类型
typedef [public,uuid(7442df10-466d-11d3-be72-0008c719118c)]
BSTR test_ObjectID;

-------------------
上面的代码在VB.Net中用作:

代码

昏暗的obj作为testClasss.test_ObjectID

在任何功能内

obj =字符串值"

---------------------
should b used in C++:

Class Name : testClasss

code:

// Test Object Id Type
typedef [public, uuid(7442df10-466d-11d3-be72-0008c719118c)]
BSTR test_ObjectID;

-------------------
above code Used as In VB.Net :

code

Dim obj as testClasss.test_ObjectID

within Any function

obj = "string value"

---------------------
is this possible..?


是否要使用VB.NET中的某些C ++代码,最好的解决方案是使用C ++/CLI并使用托管代码在VB.NET和C ++.

If you want to uses some C++ code from VB.NET, the best solution is to uses C++/CLI and uses managed code to interface between VB.NET and C++.

class RegularCppClass
{
};

public ref class CppCliClassForVb
{
public:
    property System::String ^Test;
    int GetCpuSpeed();

private:
    // This member cannot be used directly from VB. You will need to add 
    // appropriate member (property or method) to CppCliClassForVb.
    // Also, you will need to do proper memory management of that object
    // by properly defining finalizer and destructor as appropriate.
    RegularCppClass *regularCppClass;
};



Visual C ++中的析构函数和终结器 [http://msdn.microsoft.com/zh-CN/library/481fa11f(v=VS.100).aspx [ ^ ]).

通过在C ++代码和VB之间使用托管层,从VB使用将更加简单.您只需要添加对该DLL的引用.

顺便说一句,您的C ++代码将需要以托管方式进行编译,但要支持标准C ++(假设您要使用常规C ++代码).也就是说,您需要选项/clr( http://msdn.microsoft.com/en-us/library/k8d11d4s.aspx [ ^ ]).此选项在您的项目设置中可用.



Destructors and finalizers in Visual C++[^]

That class can uses regular C++ object if it need to. C++ object need to be allocated by pointer or reference.

If you need in some case to go the other way (a C++ class need to have an hadle to a managed object, you will need gcroot< > (http://msdn.microsoft.com/en-us/library/481fa11f(v=VS.100).aspx[^]).

By using a managed layer between your C++ code and VB, it will be much simpler to uses from VB. You will just have to add a reference to the DLL.

By the way, your C++ code will need to be compiled as managed but with support for standard C++ (assuming you want to uses regular C++ code). That is, you need the option /clr (http://msdn.microsoft.com/en-us/library/k8d11d4s.aspx[^]). This option is available in your project settings.


这篇关于在C ++ dll中需要一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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