473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Migrating VC++ 6.0 apps to .NET

We are considering the ways to migrate our VC++ 6.0 applications to .NET
platform.
It would be nice to rewrite them completely in C#, but due to the time
constraints
this option is out of question. We started from rewriting some dll in C# in
Visual
Studio .NET. Now we face chalenges of interoperation between old VC++ 6.0
apps and new .NET C# components. To solve this problem we considered the
following options:

1) Recompile old VC++ 6.0 app in Visual Studio .NET without /CLR and use COM
introperability to connect this app and new .NET C# components. It works more
or less OK as long as new .NET C# component expose interfaces. But it is
extremely difficult to access just methods of the class whish is not exposed
as interface in .NET C# component. TBLexp automatically creates interfaces
for such classes and this is complete mess. One methods somehow become
property, names are hardly recognizable etc.

So I tried another approach.

2) Recompile old VC++ 6.0 app in Visual Studio .NET with /CLR and use "It
just works" approach. In this case I have no troubles to access interfaces or
classes from new .NET C# component. However I very quickly discovered the
managed/unmanaged code interaction nightmare. The new .NET C# component
methods of course require managed parameters, and rest of the old VC++
application code of course expects unmanaged types.

We don't want to convert the old VC++ application code to Managed C++ in one
shoot, so the idea was to keep old application code intact (may be with minor
changies) and just recompile it in Visual Studio .NET to gain easy access to
new .NET C# components.

But because of this managed/unmanaged hell I can't even make simple function
call to new .NET C# components. For example see the following code segment:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unsigned char cMessage __gc[] = new unsigned char __gc[256];
unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];

....

// Call to new .NET C# component
m_pCommInt->SendCommand(cMessage, &cResult ) ;

....

strncpy((unsigned char*)&cBuf[0], ((unsigned char*)&cResult[0]) + 3,
(int)cResult[2]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The last line causes error C2440: 'type cast' : cannot convert from
'unsigned char __gc *' to 'unsigned char *' Cannot convert a managed
type to an unmanaged type

I understand that strncpy doesn't understand managed types, but it means
that in
this case we won't be able easily migrate our old app to .NET platform. Lots
of
changies will be required to old app to make it interoperate with new .NET
C# component.

Are there other ways to make old VC++ 6.0 app to interoperate with new .NET
C# component?

Can anyone suggest a better way for old VC++ 6.0 app to interoperate with
new .NET C# component?

Can anyone suggest recommend a good example of old VC++ 6.0 app
interoperating with new .NET C# component?

Can anyone clearly explain how to fix code segment above with strncpy
function causing C2440 error?

Can anyone provide good examples how to convert array array of managed types
to unmanaged e.g. unsigned char cManaged __gc[] to unsigned char
cUnmanaged[256]?

Most of the examples and methods in MSDN are about other way around
situation when new .NET app calls old legacy component (P/Invoke etc).
Nov 17 '05 #1
1 1854
You need to pin the arrays and then passed the pinnen version. You do that
by pinning one of the elements (by convention the first one).

See the docs for the __pin keyword.

Ronald Laeremans
Visual C++ team

"Steve" <St***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
We are considering the ways to migrate our VC++ 6.0 applications to .NET
platform.
It would be nice to rewrite them completely in C#, but due to the time
constraints
this option is out of question. We started from rewriting some dll in C#
in
Visual
Studio .NET. Now we face chalenges of interoperation between old VC++ 6.0
apps and new .NET C# components. To solve this problem we considered the
following options:

1) Recompile old VC++ 6.0 app in Visual Studio .NET without /CLR and use
COM
introperability to connect this app and new .NET C# components. It works
more
or less OK as long as new .NET C# component expose interfaces. But it is
extremely difficult to access just methods of the class whish is not
exposed
as interface in .NET C# component. TBLexp automatically creates interfaces
for such classes and this is complete mess. One methods somehow become
property, names are hardly recognizable etc.

So I tried another approach.

2) Recompile old VC++ 6.0 app in Visual Studio .NET with /CLR and use "It
just works" approach. In this case I have no troubles to access interfaces
or
classes from new .NET C# component. However I very quickly discovered the
managed/unmanaged code interaction nightmare. The new .NET C# component
methods of course require managed parameters, and rest of the old VC++
application code of course expects unmanaged types.

We don't want to convert the old VC++ application code to Managed C++ in
one
shoot, so the idea was to keep old application code intact (may be with
minor
changies) and just recompile it in Visual Studio .NET to gain easy access
to
new .NET C# components.

But because of this managed/unmanaged hell I can't even make simple
function
call to new .NET C# components. For example see the following code
segment:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unsigned char cMessage __gc[] = new unsigned char __gc[256];
unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];

...

// Call to new .NET C# component
m_pCommInt->SendCommand(cMessage, &cResult ) ;

...

strncpy((unsigned char*)&cBuf[0], ((unsigned char*)&cResult[0]) + 3,
(int)cResult[2]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The last line causes error C2440: 'type cast' : cannot convert from
'unsigned char __gc *' to 'unsigned char *' Cannot convert a managed
type to an unmanaged type

I understand that strncpy doesn't understand managed types, but it means
that in
this case we won't be able easily migrate our old app to .NET platform.
Lots
of
changies will be required to old app to make it interoperate with new .NET
C# component.

Are there other ways to make old VC++ 6.0 app to interoperate with new
.NET
C# component?

Can anyone suggest a better way for old VC++ 6.0 app to interoperate with
new .NET C# component?

Can anyone suggest recommend a good example of old VC++ 6.0 app
interoperating with new .NET C# component?

Can anyone clearly explain how to fix code segment above with strncpy
function causing C2440 error?

Can anyone provide good examples how to convert array array of managed
types
to unmanaged e.g. unsigned char cManaged __gc[] to unsigned char
cUnmanaged[256]?

Most of the examples and methods in MSDN are about other way around
situation when new .NET app calls old legacy component (P/Invoke etc).

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shai Levi | last post by:
Hi, I'm trying to migrate native c++ class to managed c++ class. The native class header definition looks as: class NativeClass { public: typedef void (CbFunc1)(int n,void* p);
8
by: The unProfessional | last post by:
To the VC .Net'ers out there... I noticed alot of strange behavior in the way VC .Net apps behave in the IDE. It's a bit odd, so maybe people have workarounds. I'm worried to devote my project...
7
by: Rachete | last post by:
Can any one give me a couple of good reasons (advantages) to use VC++ 2005 versus using VC# 2005 (especially for a middle tier component development)? rachete.
3
by: Mike Doyle | last post by:
Hi, I'm looking at migrating our existing from Visual Studio (6.00) C++ code to the .NET version of C++ (unmanaged) Can anyone point me towards documention or an overview of this ? Thanks in...
8
by: david_75 | last post by:
I wonder if the transistion from the project written in VC++ 6.0 to VC++ .NET requires a lot of code changes (if any) if I compile the project in native code (or unmanaged code) without using the...
11
by: danip | last post by:
Hi there, I need to do the following: 1. Migrate a whole solution (with tens of projects) from VC 6.0 to VC 8.0. The project has a lot of MFC templates like CArray, and many error are poping out,...
34
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
4
by: =?Utf-8?B?QXJqdW4=?= | last post by:
Hi, After migrating my application from VC++ 6.0 to VC++ 2005, I receive the error C2593 'operator +=' is ambiguous. It refers to the following line: Name += pManager->GetAgentName(); ...
4
by: VikrantS | last post by:
Hi, I am migrating code from VS 6.0 to VS2008. The Code compiles in VS 6.0 but gives the following errors when compiled in VS 2008, --- \Program Files\VC\atlmfc\include\afxcmn.inl(376) : error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.