获取对正在运行的vb.net Windows窗体应用程序的对象引用 [英] Get object reference to a running vb.net windows forms application

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

问题描述

我创建了一个名为ODTuner的Windows窗体应用程序。它是使用VS2010在vb.net中编写的。我试图从我正在为另一个应用程序编写的插件中获取对该应用程序的运行实例的对象引用。但是,当作出任务时:



Dim odt as Object

odt = GetObject(,ODTuner.Application)



我得到一个错误,说对象变量或没有设置块变量如果我使用CreateObject从VBScript执行它,我得到一个错误说,ActiveX组件不能创建对象。



现在,我相信我在ODTuner中设置了相应的属性,如下所示:



< comvisibleattribute(true),> Guid(896746B9-ECEE-4EB3-9DB7-BAC2D318D07C),_

ProgId(ODTuner.Application),_

ClassInterface(ClassInterfaceType.None)> _

公共类ODTuner



起初,我认为一定不能正确注册,即使ComVisibleAttribute设置为true,并在AssemblyInformation中选中Make Assembly COM Visible。以管理员身份登录时,我搜索了注册表,并确实在Computer\HKEY_CLASSES_ROOT \下找到了使用正确GUID注册的注册表。哦,我也试过用regasm手动注册它。



所以,我的问题是,如果它确实出现在注册表中,为什么我会收到错误。我确实找到了一个帖子,说你不能使用GetObject来获取对Visual Basic中创建的类的对象引用(它没有特别提到.NET)。这对我来说没有意义,但是如果它是真的,你怎么得到一个在VB中创建的类的对象引用?



我有这样的感觉在VS中手动更改了它自动处理的东西,并且损坏了某些东西,但是我搜索并搜索并且无法弄清楚为什么这不起作用。



任何帮助都会是赞赏。我已经被困在这个太久了。



更新:对象变量或With block变量未设置错误是由不同的问题引起的。正确的错误消息是无法创建ActiveX组件。



odt = CreateObject(ODTuner.Application



OR



odt = GetObject(,ODTuner.Application)



都给出了这个错误。

I have created a windows forms application called ODTuner. It was written in vb.net using VS2010. I am attempting to get an object reference to a running instance of this application from a plugin I'm writing for another application. However, when the assignment is made:

Dim odt as Object
odt = GetObject(, "ODTuner.Application")

I get an error saying, "Object variable or With block variable not set" If I execute it from a VBScript using CreateObject, I get an error saying, "ActiveX Component can not create object."

Now, I believe I have the appropriate attributes set in ODTuner as follows:

<comvisibleattribute(true),> Guid("896746B9-ECEE-4EB3-9DB7-BAC2D318D07C"), _
ProgId("ODTuner.Application"), _
ClassInterface(ClassInterfaceType.None)> _
Public Class ODTuner

At first, I thought it must not be getting registered properly, even though the ComVisibleAttribute is set to true, and "Make Assembly COM Visible" is checked in AssemblyInformation. When logged in as an administrator, I searched the registry and did find it registered there with the correct GUID under Computer\HKEY_CLASSES_ROOT\. Oh, I have also tried registering it manually using regasm.

So, my question is, if it does appear in the registry, why am I getting an error. I did find a post somewhere that said that you cannot use GetObject to get an object reference to a class created in Visual Basic (it did not mention .NET specifically). This does not make sense to me, but if it is true, how do you get an object reference to a class created in VB?

I have the feeling that I changed something manually in VS that it handles automatically, and corrupted something, but I have searched and searched and cannot figure out why this does not work.

Any help would be appreciated. I have been stuck on this too long already.

Update: The "Object variable or With block variable not set" error was caused by a different problem. The correct error message is "Cannot create ActiveX component."

odt = CreateObject("ODTuner.Application"

OR

odt = GetObject(, "ODTuner.Application")

both give this error.

推荐答案

尝试注册第三方activex组件。
Try registering the third party activex component.


这篇关于获取对正在运行的vb.net Windows窗体应用程序的对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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