tags:

views:

166

answers:

4

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"&gt;
<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>
+1  A: 

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 Methods registers for callbacks. If you do not have callbacks, you don't need to call this method.

Arthur
A: 

Arthur, I just added a random string "ap_" for the prefix, does this need to be anything in particular? It seems be falling over at these 2 lines:

var appos = WScript.CreateObject ("ap.MyComponent");        
WScript.ConnectObject (appos, "ap_");

I don't have any events, just a namespace (ap) and a class called MyComponent which implements an interface.

Sorry couldn't add a comment as I cleared my cookies!

David
A: 

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);
Arthur
A: 

Thanks so much, can't seem to tick the answer as the one above from Arthur due to clearing cookies!