在 WSH Windows 脚本中测试 COM 调用

发布于 2024-08-06 03:25:42 字数 873 浏览 8 评论 0原文

我有一个工作的 C# COM 组件 dll,在 ap 命名空间中有一个名为 MyComponent 的类,该类已添加到 GAC 并成功注册。我向它添加了 Add() 调用,使用 win32 c++ exe 对其进行了测试,并成功调用了 Add() 调用,因此一切正常。

但是,我想在 WSF(Windows 脚本)中测试调用,我将下面的代码放入名为 test.wsf 的文件中,当我运行代码时,出现错误:

错误:无法连接对象,在线:
WScript.ConnectObject(appos,"ap_");

为什么连接不上!帮助!

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/WindowsScriptHost">
<job>
    <?job debug="true" ?> 
    <script language="JScript">
<![CDATA[       

// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");        
WScript.ConnectObject (appos, "ap_");

// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);


// Release object
appos = null;

  WScript.StdIn.Read(1);
]]>
    </script>
 </job>
</package>

I have a working C# COM component dll, with a class called MyComponent in the ap namespace, which is added to the GAC and registered successfully. I added a Add() call to it, tested it with a win32 c++ exe and called the Add() call successfully, so its all working.

However I want to test the call in WSF (windows script) I put the code below in a file called test.wsf, when I run the code I get an error:

Error: Could not connect object, on the line:
WScript.ConnectObject(appos,"ap_");

Why is it not connecting! Help!

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/WindowsScriptHost">
<job>
    <?job debug="true" ?> 
    <script language="JScript">
<![CDATA[       

// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");        
WScript.ConnectObject (appos, "ap_");

// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);


// Release object
appos = null;

  WScript.StdIn.Read(1);
]]>
    </script>
 </job>
</package>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两相知 2024-08-13 03:25:42

来自 MSDN:

将对象的事件源连接到具有给定前缀的函数。

http://msdn.microsoft.com/en-us /library/ccxe1xe6(VS.85).aspx

此方法注册回调。如果没有回调,则不需要调用此方法。

From MSDN:

Connects the object's event sources to functions with a given prefix.

http://msdn.microsoft.com/en-us/library/ccxe1xe6(VS.85).aspx

This Methods registers for callbacks. If you do not have callbacks, you don't need to call this method.

临走之时 2024-08-13 03:25:42

抱歉,我的回答不够准确。

WScript.ConnectObject (appos, "ap_");

此方法用于将脚本附加到 COM 对象事件。您没有事件,因此不需要调用该方法。

来自 MSDN:

将对象的事件源连接到具有给定前缀的函数。

http://msdn.microsoft.com/en- us/library/ccxe1xe6%28VS.85%29.aspx

这应该足够了:

// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");        

// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);

Sorry, my answer was not precice enough.

WScript.ConnectObject (appos, "ap_");

This method is for attaching your script to the COM Objects events. You have no events, so you don't need to call that method.

From MSDN:

Connects the object's event sources to functions with a given prefix.

http://msdn.microsoft.com/en-us/library/ccxe1xe6%28VS.85%29.aspx

This should be enough:

// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");        

// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文