Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: WMECom plugin - COM Automation  (Read 5823 times)

0 Members and 2 Guests are viewing this topic.

Banbury

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
  • I'm a llama! Mooh!
    • View Profile
WMECom plugin - COM Automation
« 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

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

Code: [Select]
// 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();
« Last Edit: September 26, 2005, 07:07:11 AM by Banbury »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: WMECom plugin - COM Automation
« Reply #1 on: September 22, 2005, 07:59:44 AM »

Wow, that sounds impressive :o Can't wait to do some tests when I get home :) Thanks, Banbury!
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re: WMECom plugin - COM Automation
« Reply #2 on: September 22, 2005, 10:03:00 AM »

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. :)
Logged
Mooh!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: WMECom plugin - COM Automation
« Reply #3 on: September 22, 2005, 02:22:14 PM »

Quote from: Banbury
- 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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: WMECom plugin - COM Automation
« Reply #4 on: September 22, 2005, 06:09:44 PM »

I tried the following code and I'm geting a "wrong type" error. What am I doing wrong here?

Code: [Select]
  var com = new WMECom();
  var word = new WMEComObject("Word.Application");

  var docs = new WMEComObject(word.Documents); // wrong type
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Banbury

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
  • I'm a llama! Mooh!
    • View Profile
Re: WMECom plugin - COM Automation
« Reply #5 on: September 23, 2005, 07:49:28 AM »

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
Logged

Banbury

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 36
  • I'm a llama! Mooh!
    • View Profile
Re: WMECom plugin - COM Automation
« Reply #6 on: September 26, 2005, 07:19:09 AM »

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:

Code: [Select]
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
Logged
 

Page created in 0.033 seconds with 19 queries.