我如何...在非托管代码中使用.NET组件 [英] How do I...Use .NET component in unmanaged code

查看:91
本文介绍了我如何...在非托管代码中使用.NET组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MFC ActiveX VC ++项目,它创建了一个在一些VC#.NET项目中使用的控件。为什么我没有使用.NET用户控件来开发这个控件,因为GDI在绘制我想要的东西时比GDI +更快控件显示。当它连接到数据库时,控件运行良好。现在我希望它可以接受.NET DataSet作为其数据源。例如,如果我在我的.NET项目中使用此ActiveX控件,并将其放在VC中的表单中#project,例如我想在Form构造函数中有这样的东西:



I have a MFC ActiveX VC++ project that create a control to use in some VC# .NET projects.Why I didn't use .NET user control to develop this control because GDI is faster than GDI+ in drawing what I want this control shows.The control works well when it connects to database.Now I want it can accept a .NET DataSet as its datasource.For example if I use this ActiveX control in my .NET project,and I put it in a Form in VC# project,for example I want to have something like this in Form constructor:

public MyForm()
{
       InitializeComponent();
       
       //What I want to achieve
       DataSet dsSource=new DataSet();
       //Populate dsSource somehow
       MyActiveX.DataSource=dsSource;
}



或者我可能在非托管代码中没有这种类型的属性(我还不知道)所以我必须在一个MFC ActiveX控件中的成员函数。


or maybe I can't have this type of properties in unmanaged code(I don't know yet) so I have to implement it in a member function in MFC ActiveX Control.

public MyForm()
{
       InitializeComponent();
       
       //What I want to achieve
       DataSet dsSource=new DataSet();
       MyActiveX.SetDataSource(dsSource);
}



无论如何将DataSet(或任何其他.NET类实例)传递给ActiveX控件并在非托管代码中使用它是怎么回事? .NET类可以在VC ++非托管代码中使用吗?



感谢任何指南或参考。


Is there anyway to pass a DataSet (or any other .NET class instance) to an ActiveX control and use it inside unmanaged code?how a .NET class can be used in VC++ unmanaged code?

Thanks for any guide line or reference.

推荐答案

你通常会'(因为总有例外')使用COM Interop



iirc有一个名为tlbimp的工具为你生成一个'包装' - 看看是否这有助于: -



http:// examples。 oreilly.com/9780596527570/COMIntegrationC%23Nutshell2ndEd.pdf [ ^ ]



如果没用,请搜索C#,COM,Interop,TLBIMP



多年前我有一个完整的指南,但是现在找不到:-(



- 实际上,重新审视你的问题,我认为我没有回答它 - 我原本以为你使用的是C#.NET中的COM / ActiveX对象 - 抱歉[/ edit]
You would 'generally' (because there's always an exception') use COM Interop

iirc there's a tool called tlbimp that generates a 'wrapper' for you - see if this helps :-

http://examples.oreilly.com/9780596527570/COMIntegrationC%23Nutshell2ndEd.pdf[^]

If that's no use, do a search for C#, COM, Interop, TLBIMP

I had a whole guide on this many years ago, but cant find it now :-(

[edit] - actually, relooking at your question, I don't think Ive answered it - I originally thought you were using a COM/ActiveX object in C# .NET - sorry [/edit]


这篇关于我如何...在非托管代码中使用.NET组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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