[已解决]如何将C#.Net应用程序集成到C ++非托管项目中 [英] [Solved] How to integrate C#.Net application into C++ Unmanaged project

查看:133
本文介绍了[已解决]如何将C#.Net应用程序集成到C ++非托管项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

考虑到它是软件的单独模块,我必须将C#.Net应用程序集成到C ++非托管MFC应用程序中.我已经尝试过在此处发布的方法.我遵循了所有步骤,但是由于Visual Studio 2008拒绝构建具有类库输出类型的项目而无法帮助我,生成了.dll文件,但是当我尝试在某些情况下导入该文件时,我遇到了未注册.dll的问题C ++项目.基本上,我在C#.Net表单中有一个文本框和一些按钮,我想将此表单以及在C#.Net应用程序中调用的所有事件和方法合并到一个c ++项目中.任何帮助将不胜感激.

Hello,

I have to integrate a C#.Net application in a C++ un managed MFC application considering it a separate module of the software. I have tried the method posted here. I followed all the steps but it could not help me because Visual Studio 2008 refused to built my project having output type as Class Library, .dll file is generated but I face the problem of .dll not registered when I try to import that in some C++ project. Basically I have a text box and some buttons in my C#.Net form and I want to merge this form into a c++ project along with all the events and methods I called in C#.Net application. Any help would be appreciated.

推荐答案

首先,集成应用程序"的想法本质上是不好的.库应该是集成的"(实际上只是在使用),而不是应用程序.这不是大多数应用程序的目的.

另外,我不建议这样做,因为这样做可能很困难也很尴尬(相反,在.NET中使用非托管代码会容易得多).

一种方法是使用在.NET中开发并在非托管代码中使用的COM组件.这并不难,但是使用过时的技术很尴尬,特别是如果您意识到开发整个.NET技术是为了摆脱这种情况并引入纯OOP技术.

另一种方法颇为奇特,但它基于严格的CLR标准:将方法直接导出到不受管理的方法.许多人会说这是不可能的,但这不是事实. CodeProject文章的数量证明了这种方法的有效性.请查看我过去的答案:
在MFC中加载C#DLL [如何使用在Visual Basic 6.0中的Visual Basic 2008中创建的dll [从Unmanged Code VC ++用C#调用托管DLL [ ^ ],
http://www.codeproject.com/Answers/236759/网络中托管或不受管理的API#answer2 [
First of all, the idea to "integrate application", no matter what is it, is inherently bad. Libraries should be "integrated" (in fact, just used), not applications. This is not the purpose of most applications.

Also, I would not advise going this way, because this could be either difficult or awkward thing to do (doing just the opposite, using unmanaged code in .NET is much easier).

One approach is using COM components developed in .NET and used in unmanaged code. This is not hard to do, but it''s awkward to use the obsolete technology, especially if you realize that the whole .NET technology was developed to get away from such things and introduce purely OOP technology.

Another method is rather exotic but is based on firm CLR standards: direct export of methods to unmanaged. Many would say it''s impossible, but that''s not true. The number of CodeProject articles demonstrated validity of such approach. Please see my past answers:
loading C# DLL in MFC[^],
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
http://www.codeproject.com/Answers/236759/APIs-in-Net-Managed-or-UnManaged-Code#answer2[^].

—SA


这篇关于[已解决]如何将C#.Net应用程序集成到C ++非托管项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆