从VC ++ 6.0 Dll迁移到VC ++ 2010 Dll的问题 [英] Issue in migration of VC++6.0 Dll to VC++2010 Dll

查看:101
本文介绍了从VC ++ 6.0 Dll迁移到VC ++ 2010 Dll的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目在VC ++ 6.0中创建.该项目有一个exe文件和5个dlls文件.

该项目已从VC ++ 6.0迁移到Visual Studio 2010.现在exe在C#2010中,而Dlls在VC ++ 2010中.

我的问题是,我必须在C#exe中访问VC ++ dll的类成员变量,因此为此,在VC ++ dll的类中,我在头文件中添加了"ref".
下面是VC ++ 2010 dll的代码段

ShipInfo.h代码(头文件)

命名空间ShipInfoDllNamespace
{
公共参考类ShipInfo
{
私人:
静态浮点数m_fDirection;
}

ShipInfo.cpp代码(源文件)

命名空间ShipInfoDllNamespace
{
float ShipInfo :: m_fDirection;
}


现在,如果添加了"ref",那么我将收到错误消息,如–

错误C3366:"ShipInfoDllNamespace :: ShipInfo :: m_fDirection":必须在类定义中定义托管类型的静态数据成员.
-------------------------------------------------- ---------------------
而且,如果我删除"ref"则没有错误,但是我无法访问C#exe类中的VC ++ Dll成员变量.

任何人都可以建议我如何解决此问题.在此先感谢.

I am having one project, which is created in VC++6.0 .This project having one exe file and 5 dlls files.

The project is migrate to Visual Studio 2010 from VC++6.0. Now the exe is in C# 2010 and Dlls are in VC++ 2010.

My problem is, I have to access VC++ dll’s class member variables in the C# exe, so for this in VC++ dll’s class, I have added "ref" in the header files.

Below is code snippet of VC++ 2010 dll

Code of ShipInfo.h (header file)

namespace ShipInfoDllNamespace
{
public ref class ShipInfo
{
private:
static float m_fDirection;
}

Code of ShipInfo.cpp (source file)

namespace ShipInfoDllNamespace
{
float ShipInfo::m_fDirection;
}


Now if "ref" is added then I am getting error as –

error C3366: ''ShipInfoDllNamespace::ShipInfo::m_fDirection'' : static data members of managed types must be defined within the class definition

-----------------------------------------------------------------------
And if i remove "ref" then NO error, but then i can''t access VC++ Dll member variable in C# exe class.

Can anyone advice me how to resolve this issue. Thanks in advance.

推荐答案

在非托管C ++中,类的静态数据成员必须在文件范围内初始化,而您必须在C ++中对类本身进行相同的操作/CLI

检查一下:
http://msdn.microsoft.com/en-us/library/27tfb08h.aspx [ ^ ]

另请查看这篇文章,以了解mangaed c ++的介绍.很好.
C ++/CLI的实际应用-实例化CLI类 [ ^ ]
In unmanaged C++, Static data members of classes must be initialized at file scope, while you have to do the same in the class itself in C++/CLI

check this :
http://msdn.microsoft.com/en-us/library/27tfb08h.aspx[^]

Also check this article for intro to mangaed c++. It''s good one.
C++/CLI in Action - Instantiating CLI classes[^]


您没有从VC ++ 6.0迁移到VC ++ 2010,而是要迁移:1)从本机平台迁移到由.NET实现的CLR平台; 2)不是从一个C ++版本到另一个版本,而是从一种语言到另一种非常不同的语言,称为C ++/CLI.

恐怕您没有意识到这两个事实中的一个或两个.

恐怕您可能没有意识到不必迁移到.NET.您可以使用本机平台;在这种情况下,您的项目将向后兼容(如果您的旧代码中没有任何愚蠢的东西);项目的转换将自动完成.

因此,我建议您要么继续使用本机开发和C ++,要么学习.NET和C ++/CLI(或其他一些.NET语言),但是您可能需要从头开始. CLR平台与Windows有很大不同:它是面向对象的,受管理的,基于JIT编译的等.对于Windows和C ++开发,飞跃非常大. (对于习惯于某些其他语言和系统的开发人员来说,这自然而然;例如,来自Ada,Delphi Pascal等公司的产品.)

—SA
You are not migrating from VC++6.0 to VC++ 2010, you are migrating: 1) from native platform to CLR platform implemented by .NET; 2) not from one version of C++ to another one, but from one language to a very different language called C++/CLI.

I''m afraid you do not realize one or both of those two facts.

I''m afraid you might not realize that you don''t have to move to .NET. You can stay with native platform; in this case your project would be pretty much backward-compatible (if you don''t have anything silly in your legacy code); and the conversion of the projects would be done automatically.

So, I suggest you either stay with native development and C++ or learn .NET and C++/CLI (or some other .NET language(s)), but you probably need to start from scratch. The CLR platform is very different from Windows: it is object-oriented, managed, based on JIT compilation, etc. For a Windows and C++ development the leap is pretty big. (And for developers used to some other languages and systems it would be more than natural; for example, from Ada, Delphi Pascal and more.)

—SA


这篇关于从VC ++ 6.0 Dll迁移到VC ++ 2010 Dll的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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