How to migrate from C++ COM to C++CLI

非 Y 不嫁゛ 提交于 2019-12-08 00:57:27

问题


I have a C++ DLL that exposes stuff via COM. I want to convert it to C++/CLI that exposes a managed interface. Ideally I just add CLI and convert interfaces one by one. So far I haven't succeeded in anything, so I'm looking for a specific strategy.


More detail: A long time ago, I created an app using COM to communicate back and forth between C# and C++. I'm sick of COM, and the registration and the hoop jumping needed on the C++ side.

I want to use C++/CLI, and get the whole thing working as managed code with the occasional call from C++/CLI to native libraries I'm using.

Can anyone suggest a gentle migration path, such that I can have both CLI and COM going, and convert things over class by class testing as I go? Or something like that.

To be clear: I currently have native C++ code defining and implementing COM interfaces. I have C# code using COM attributes to export classes. All this stuff gets registered for COM interop, and there are calls in both directions. I hope to switch the C++ to CLI and switch to managed classes in C++ rather than COM classes.

Question updated for Ramhound: Anyway, I'm running into brick walls. Turning on /clr on a C++ dll gives me link errors from other stuff trying to connect to that C++ code. (Unreadable ATL/COM messages of the sort that drive me away from C++)


回答1:


You may want to read through this, as it provides some different approaches and considerations involved: http://msdn.microsoft.com/en-us/magazine/dd315414.aspx

Here is a simple example of how to use interop in C++/CLI, where you could define a method or two and add more as you go: http://blogs.msdn.com/b/borisj/archive/2006/07/29/683061.aspx




回答2:


please follow this

http://msdn.microsoft.com/en-us/magazine/cc163494.aspx

use tlimp to generate a COM unmanaged DLL to a managed DLL

is pretty simple!!!



来源:https://stackoverflow.com/questions/9265835/how-to-migrate-from-c-com-to-ccli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!