Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 VC10.0
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 30-Jan-12 19:18pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Lakamraju Raghuram at 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
SAKryukov at 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)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 31 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100