将应用程序控件嵌入我的新应用程序中 [英] Embed application Control into my new application

查看:76
本文介绍了将应用程序控件嵌入我的新应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新学员。我有一个跟踪查看器应用程序和跟踪查看器Control OCX文件,它们是用C ++编写的(我有源代码)用于记录跟踪日志(功能类似于Windows事件日志)。现在我正在编写一个C#Console应用程序来过滤和提取跟踪日志中的数据。

我需要在我的C#应用​​程序中使用traceviewer应用程序加载跟踪文件,我想我需要将这个OCX控件嵌入到我的代码中。但是对于如何做到这一点,我没有明确的想法。

现在我正在考虑使用AppDomain创建一个新域并在这个新应用程序中处理应用程序,并从跟踪查看器Control中调用方法。

任何人都可以分享您的想法/建议/我应该怎么做的经验或者我应该寻找哪种知识?



非常感谢提前。

Hi, I am a new learner for C#. I have a trace viewer application and trace viewer Control OCX file, they were writen in C++(I have the source code)for record trace logs(Functionally similar to windows Event logs). Now I am writing a C# Console application to filter and extract data from the trace log.
I need to load trace file using the traceviewer application in my C# application, I think I need to embed this OCX Control into my code. But for how to do that, I have no clear ideas.
Now I am thinking of using AppDomain to create a new domain and process the application in this new application, and call methods from trace viewer Control.
Can anyone shares your ideas/Advice/Experience on how I should do or which kind of knowledge I should look for?

Many thanks in advance.

推荐答案

谢谢SA,我现在可以理解你想要告诉我的内容。



我无法通过项目成功添加我的.ocx库 - >添加参考 - > COM /浏览窗口 - >显示以下错误的myocx.ocx:

无法添加对... \ xxxx.ocx的引用。请确保该文件可访问,并且是一个有效的程序集或COM组件。

这让我误解了一段时间,在找到正确的理由之前,我误导了另一个对dllimport的指责......



关键点应该是:



1.托管代码和非托管代码。这是我理解为什么我不能将myocx.ocx作为其他.NET dll库添加引用的核心点。总而言之,如果我想将我的非托管myocx.ocx添加到托管C#项目中,我需要佩戴它管理衣服,因此.NET环境可以将其与其他托管库(即互操作包装器)相同。这可以通过Tlbimp.exe或VB.NET方便地完成。



2.当COM组件没有在本地Visual Studio上构建时,在我的情况下从公司下载源代码服务器。在本地机器上需要Dll注册才能被VB.NET IDE包装(通过上面的添加引用自动完成,你可以在project / obj / Debug下找到interop.myocx.dll文件)或者Tlbimp .exe工具。因为所有COM组件都由GUID而不是本地计算机上的文件位置标识(您可以检查使用Regeditor.exe-> HKEY_CLASSES_ROOT / CLSID),因此Tlbimp.exe将使用此GUID到达'myocx.ocx '包裹它时。在本地visual studio中构建COM组件时,它将在COM组件成功构建时自动注册。如果没有,该组件需要在管理员下手动注册Regsvr32.exe(这里也有问题!!)



3. A小提示。在我的情况下,我得到了我的同事的建议我们通常生成interop.myocx.dll并上传到我们的源代码服务器,所以如果幸运的话你可以直接找到interop dll文件,你将不会有任何问题需要添加引用它作为普通的托管dll。因此,如果可能的话,首先请求或搜索interop dll作为第1步。



祝你好运!
Thanks SA, I can now understand what you wanted to show me.

I couldn't successfully add my .ocx library by project->Add reference->COM/Browse window-> "myocx.ocx" with the following error shows up:
A reference to '...\xxx.ocx' could not be added.Please make sure that the file is accessible, and that it is a valid assembly or COM compoent.
This bugged me for a while and before I find the right reason I was mislead to another direaction for "dllimport"...

The key points for me should be:

1. Managed code and Unmanaged code. This is the core point for me to understand why I couldn't add reference with "myocx.ocx" as other .NET dll libraries. So conclution is if I want to add my unmanaged "myocx.ocx" into managed C# project, I need to wear it a "manage clothes" so .NET enviroment can take it as the same with other managed libraries, which is interop wrapper. This can be done by either Tlbimp.exe or VB.NET conveniently.

2.When COM component is not builded on local Visual studio, in my case downloaded from company source code server.It need Dll regsitration on local machine before it can be wrapped by VB.NET IDE(automatically done by add reference above, you can find the "interop.myocx.dll" file under project/obj/Debug) or Tlbimp.exe tool.Because all COM components are identified by GUIDs instead of file location on local machine(You can them check use Regeditor.exe->HKEY_CLASSES_ROOT/CLSID),so Tlbimp.exe will use this GUID to reach 'myocx.ocx' when wrap it. When you build COM component in local visual studio, it will automatically register for you when COM component is successfully built. If not, the component need a manual registration with Regsvr32.exe under administrator(Here also can have problems!!)

3. A small tip. In my case, I got advise from my colleague we usually generate the "interop.myocx.dll" and upload to our souce code server, so if luckily you can find the interop dll file directly, you won't have any problem to add reference to it as a normal managed dll. So ask or search for interop dll first as step 1 if possible.

Good luck!


这篇关于将应用程序控件嵌入我的新应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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