Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
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.
Posted

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[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Jan-12 1:05am    
Good reply, my 5.

You know, I don't feel OP realizes where the migration goes, so I added some clarification in my answer, please see.
--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
 
Share this answer
 
Comments
Lakamraju Raghuram 31-Jan-12 1:12am    
"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)" ---

Bingo .... hope the OP got the gist of that statement.

+5
Sergey Alexandrovich Kryukov 31-Jan-12 1:35am    
Hopefully... Thank you, Lakamraju.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900