在 WSH Windows 脚本中测试 COM 调用
我有一个工作的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 MSDN:
http://msdn.microsoft.com/en-us /library/ccxe1xe6(VS.85).aspx
此方法注册回调。如果没有回调,则不需要调用此方法。
From MSDN:
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.
抱歉,我的回答不够准确。
此方法用于将脚本附加到 COM 对象事件。您没有事件,因此不需要调用该方法。
来自 MSDN:
将对象的事件源连接到具有给定前缀的函数。
http://msdn.microsoft.com/en- us/library/ccxe1xe6%28VS.85%29.aspx
这应该足够了:
Sorry, my answer was not precice enough.
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: