Re: Migrating VC++ 6.0 apps to .NET
From: Ronald Laeremans [MSFT] (ronaldl_at_online.microsoft.com)
Date: 08/23/04
- Next message: Chris: "using managed arrays ???"
- Previous message: Nadav: "Re: Injecting Code to an existing PE"
- In reply to: Steve: "Migrating VC++ 6.0 apps to .NET"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 23 Aug 2004 10:10:04 -0700
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" <Steve@discussions.microsoft.com> wrote in message
news:EE74F79C-CA35-487B-850C-50C4007577B4@microsoft.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).
- Next message: Chris: "using managed arrays ???"
- Previous message: Nadav: "Re: Injecting Code to an existing PE"
- In reply to: Steve: "Migrating VC++ 6.0 apps to .NET"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|