Wintermute Engine Forum
Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: Banbury on September 22, 2005, 07:21:41 AM
-
Hi,
after two failed attempts to create something useful for WME, I have created something that is releasable and hopefully useful.
WMECom is a plugin that adds COM Automation support to WME scripting. There are a lot of applications and libraries out there that support COM/OLE, e.g. MS Office or MS XML, and these can now be used within WME (with reasonable limitations). See below for an example, that uses MS XML to create an XML document.
Update:
Version 1.01:
- fixed bug where IDispatch properties were returned as boolean (probably a bug in WME)
- removed 9 parameter limitation from function calls
WMECom 1.01 (http://www.nightsoft.net/banbury/download/WMECom101%2Ezip)
There is a short ReadMe in the package, but I had no time (or inclination :D) to write a complete documentation. The sample shows every feature of the plugin. And if you have questions, don't hesitate to ask me. I will try to help as best as I can.
Greetings
Banbury
// this class initializes COM support and has to be a created once (and only once) before you can use any other COM object
var com = new WMECom();
// Create a new COM object
var xml = new WMEComObject("MSXML2.DomDocument");
// This variable holds the original pointer to the node
var node = xml.createElement("Node1");
// and it is passed to the function without wrapping
xml.appendChild(node);
// We have to wrap it here, before we can use properties and functions.
var o_node = new WMEComObject(node);
o_node.text = "This is a new node.";
Game.LOG(xml.xml);
// Objects of type WMEComObject should be released when no longer needed.
o_node.Release();
xml.Release();
-
Wow, that sounds impressive :o Can't wait to do some tests when I get home :) Thanks, Banbury!
-
Hey Banbury,
cool, thanks a lot for sharing that masterpiece. ;D
As XML fan I already like the example (although I never heard of MS XML actually... oops!). I'm curious to see more examples where this will be used, I don't have enough fantasy to think of what might be possible to use with this without rewriting it in C++ now. :)
-
- functions can use up to 9 parameters, since WME gives no indication, how many parameters were passed to a plugin.
It is possible to check the number of parameters passed to a method. When a method is called, there is an int value on top of the stack, specifying the number of parameters. But you must not call the Stack::ExpectParams() in case you read this value yourself.
-
I tried the following code and I'm geting a "wrong type" error. What am I doing wrong here?
var com = new WMECom();
var word = new WMEComObject("Word.Application");
var docs = new WMEComObject(word.Documents); // wrong type
-
Hi,
I just tested your code and for some reason word.Documents returns a boolean value. ???
It's not easy to map a COM variant to a WME IWMEValue. I will check this out as soon as I can and try to fix it.
And thanks for the tip on using the stack, I will change the plugin accordingly.
Greetings
Banbury
-
Hi,
I have found the issue and semi fixed it. IDispatch properties are now returned as integers and wrapped correctly. But using them as function parameters will now result in a type error. But IDispatch values returned by a function work as expected.
I think there is bug in the WME plugin system. To discern IDispatch pointers from integers, I have assigned them as a property of a IWMEValue. This changes the type of the IWMEValue to [object], which I can test for. This does work for return values of functions. The same code used to return a value by the GetProperty function, returns a boolean value.
The code I have used looks like this:
IWMEValue *v1 = Game->CreateValue();
v1->SetVal("Pointer");
IWMEValue *v2 = Game->CreateValue();
v2->SetVal(v.intValue); // This is the IDispatch pointer cast to integer
v1->SetProperty("p", v2);
Value->SetVal(v1); //This is the return variable of GetProperty
Maybe you could test this?
Greetings
Banbury