处理Windows窗体应用程序 [英] Dealing with windows form application

查看:83
本文介绍了处理Windows窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里处理MOF,代码是用C ++编写的,用于从MOF类文件中提取实例......我已经完成了编码部分



现在出现问题我要创建一个表单,它将由一个标签,文本框和一个按钮组成,当我点击按钮事件时应该触发MOF的C ++代码并将任何结果转回表格



plz help

解决方案

这是通过的P / Invoke。您需要使用C ++代码创建DLL,导出所需的函数。您不能也不需要将此DLL添加到C#项目中。相反,您应该创建一些具有从DLL导出的函数的静态声明的类,并应用 System.Runtime.InteropServices.DllImportAttribute 。如果您正确执行,您将在托管代码中引用DLL。有关帮助和代码示例,请参阅: http://msdn.microsoft.com/en -us / library / system.runtime.interopservices.dllimportattribute.aspx [ ^ ]。



由于类型不同,这可能有点棘手。您应该使用怎样学习 System.Runtime.InteropServices.MarshalAsAttribute ,有时 InAttribute OutAttribute OptionalAttribute ,请参阅 http://msdn.microsoft.com/en-us/library/9esea608.aspx [ ^ ]和引用。



替代方法是使用混合模式(托管+非托管)C ++项目,您可以在其中混合使用C ++和C ++ / CLI代码。这是将C ++声明包装到C ++ / CLI托管类型并使其可供任何.NET程序集访问的方法。通过这种方式,您可以将此DLL引用为普通的.NET程序集。







在Microsoft文档中进行更改后,对P / Invoke和C ++ / CLI 隐式P / Invoke 的最充分链接是:

https://msdn.microsoft.com/en-us/library/ms235282.aspx [ ^ ]。



-SA

I'm dealing with MOF here and the code is written in C++ which is used to extract the instances from the MOF class file ...and i've completed the Coding part

Now here comes the problem i want to create a "Form" which will consist of One "label","textbox" and a "button" and when i click on button event should trigger the C++ code for MOF and whatever results are transferred back to the "Form"

plz help

解决方案

This is done via P/Invoke. You need to make a DLL using C++ code, exports functions you need. You cannot and need not to add this DLL to your C# project. Instead, you should create some class with static declaration of the functions exported from your DLL and apply System.Runtime.InteropServices.DllImportAttribute. If you do it correctly, you DLL will be referenced in you managed code. See for help and code samples: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^].

This can be a bit tricky due to different types. You should use how to learn System.Runtime.InteropServices.MarshalAsAttribute, sometimes InAttribute, OutAttribute or OptionalAttribute, see http://msdn.microsoft.com/en-us/library/9esea608.aspx[^] and the references.

Alternative way is using mixed-mode (managed+unmanaged) C++ project, where you can mix C++ and C++/CLI code. This is the way to wrap C++ declarations into C++/CLI managed type and make them accessible for any .NET assembly. In this way, you can reference this DLL as a normal .NET assembly.

[EDIT]

After changes in Microsoft documentation, most adequate link to P/Invoke and C++/CLI implicit P/Invoke is this:
https://msdn.microsoft.com/en-us/library/ms235282.aspx[^].

—SA


这篇关于处理Windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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