在VC ++中使用C#类而不使用dll [英] Using C# class in VC++ without using the dll

查看:98
本文介绍了在VC ++中使用C#类而不使用dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


是否可以在不使用dll的情况下在vc ++中使用c#类.
我已经通过使用dll(将其转换为Typelibrary并通过使用Interface智能指针访问了c#类中的所有函数)来完成此操作.但是现在我需要减少开销.请帮帮我.

谢谢,
Laje ..

Hi,
Whether is to possible to use a c# class in vc++ without using the dll.
I had done it by using the dll(Which is converted to Typelibrary and accessed all the functions in the c# class by using the Interface smart pointer). But now i need to reduce the overhead. Please help me.

Thanks,
Laje..

推荐答案

没有DLL"听起来很荒谬!您也可以说没有C#文件".好吧,将DLL扩展名更改为其他名称,您将没有DLL :-)

严重地,通过本机(非托管)代码使用.NET程序集是一个问题.到目前为止,您尝试过的是吗?建议使用COM,但由于开销(您就在这里),注册表污染以及逐渐淘汰COM的总体趋势,因此,这不是一个很好的选择.

我已经回答了如何直接使用.NET Assembly.许多人会说这是不可能的,但事实并非如此.这不是众所周知的方法,但是它是鲁棒的并且基于标准.
请参阅:在MFC中加载C#DLL [
"Without the DLL" sounds ridiculous! You could also say "without C# file". Well, change DLL extension to something else, you will have without DLL :-)

Seriously, using .NET assembly by native (unmanaged) code is a problem. Is that what you tried so far? Suggested use is COM, but I this is not very good option, due to overhead (you''re right here), registry contamination and general trend of getting COM gradually obsolete.

I already answered how to use .NET Assembly directly. Many would say it is impossible, but this is not true. This is not well-known method, but it is robust and based on the standard.
See: loading C# DLL in MFC[^].

—SA


除了COM互操作之外,我认为没有其他方法可以帮助您实现这一目标. 一个是托管代码,另一个是非托管代码.
I dont think there is a way other than COM interop that can help you achieve this.
One is managed code and the other is unmanaged code.


我在这里同意abhinav的观点,因为两者都使用不同的平台,并且旧的非托管平台未修改为使用托管平台.

从软件生命周期来看,更新应用程序/语言的职责是提供向后兼容性,而不是较旧的语言获得向前的兼容性.

如果看到的话,可以通过使用DLLIMPORT(向后兼容)在托管环境中直接使用基于Win32的dll.

同样管理良好的环境为您提供了将dll转换为可在未使用的环境中使用的工具.
I agree with abhinav here, since both use different plateform and old unmanaged plateform is not modified to use managed plateform.

As per software lifecycle, it''s duty of newer application/language to provide backward compatibility not older lanaguage to gain forward compatability.

If you see, you can use win32 based dll directly in managed enviornment by using DLLIMPORT (backward compatibility).

similarly managed enviornment provided you tools to convert dll to be used in unmamnged enviornment.


这篇关于在VC ++中使用C#类而不使用dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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