COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

srod wrote:Now to correct this damn BYREF business!
:o ByRef works here like a charm. :D

Thanks for the new version! Image

Greetings ... Kiffi
Hygge
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Try passing a string BYREF !!! Bang! :wink:
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update - version 1.1.1. 7th Sept. 2008.
Apart from fixing the whole BYREF business which was completely flawed and ill thought out, I have plugged a major hole in COMate's supported parameter types, namely variants! Doh! Needless to say you can now pass variants by value or by reference (See Num3's Open Office example which is posted in this thread!)

There are a couple of things to beware of with COMate parameters (and in particular when using BYREF) which I leave to the help manual (see the page on 'COMate command strings' for details).

Finally, for those enaged with (or to :wink: ) WMI, there is a very very useful scripting utility which I came across which I have thrown into the COMate package and which should make things a lot easier!

See the nxSoftware site for the download.

Right, I'm off to study 'Event sinks' now... Let's hope I have more luck than I generally do with kitchen sinks! :wink:
I may look like a mule, but I'm not a complete ass.
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Post by eriansa »

srod wrote:Right, I'm off to study 'Event sinks' now... Let's hope I have more luck than I generally do with kitchen sinks! :wink:
Awesome :!:
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

A small example for those, who uses Outlook:

Code: Select all

IncludePath "..\"
XIncludeFile "COMate.pbi"

Define.COMateObject OutlookObject, olMsg

OutlookObject = COMate_CreateObject("Outlook.Application")

If OutlookObject

  olMsg = OutlookObject\GetObjectProperty("CreateItem(0)")
   If olMsg
    olMsg\SetProperty("to='JR_Ewing@COMate.com'")
    olMsg\SetProperty("Subject='Marco'")
    olMsg\SetProperty("Body='Write whatever you want'")
    olMsg\Invoke("Display")
;    olMsg\Invoke("send") ; if you wanna send
;    olMsg\Invoke("Quit") ; if you wanna quit

    olMsg\Release()
    Else
      MessageRequester("Sorry", COMate_GetLastErrorDescription()) 
  EndIf
OutlookObject\Release()  
Else
  MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription())
EndIf
lg
Marco
PureBasic for Windows
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Thanks for the update and for the demo.
Intrigued - Registered PureBasic, lifetime updates user
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks Marco - I've added your example to the list of demos available in the next update. :)
I may look like a mule, but I'm not a complete ass.
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Post by X »

srod wrote: Right, I'm off to study 'Event sinks' now... Let's hope I have more luck than I generally do with kitchen sinks! :wink:
Awesome! .... is this what is needed to fully use VBScript control? (ie, pass PB procedures to the script to call, etc).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I have no idea!

An event sink is used by those components/objects which offer some kind of event notification. The client program sets up an 'outgoing' interface which, if the COM object offers up this functionality, 'connects' to the object in question which then calls methods in this interface as appropriate.

This is of course particularly useful for ActiveX controls which have some kind of visual interface etc. Other objects can still use this mechanism however.

For our purposes, there really is only one way to go and that is to implement the outgoing interface as an iDispatch interface and rely upon the COM object's type-library to supply the names of the events etc. It is all very elegant. :)

Now, I know very little about VBS and the VBS ActiveX control, but if it didn't offer up the relevant interfaces for connecting through an outgoing 'sink' interface then I would be very surprised. However, my understanding is that with this mechanism, our resulting 'event procedures' would be called at the discretion of the VBS control itself, typically in response to certain events etc. Now, the only way for a script to 'arrange' for the PB 'sink' function to be called manually would be if the script could 'invoke' an event itself. This would seem to me more than plausible. In fact, can you declare your own 'events' in VBS? If so, then yes this should be more than possible!

Whether you can call compiled functions through other means in a VB script I couldn't say.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update - version 1.1.2. 8th Sept. 2008.
Version 1.1.2 adds the ability to receive events raised by COM objects (particularly ActiveX controls). My thanks to freak for his permission to use and adapt his 'EventSink' code for use in COMate. :)

New features :
  • Added a new function COMate_WrapCOMObject(). This takes any COM interface obtained by any means and attempts to wrap the underlying object up within a COMate object so that you can easily call any dispinterface functions etc. Designed for use with event handling procedures in particular.
  • A new method (SetEventHandler()) added to the COMateObject class allowing the user to attach an event-procedure to the object which is called by the underlying COM object whenever it raises an event.
  • Four additional methods added to the COMateObject class for use only within an event-procedure for retrieving parameters passed by the underlying COM object as part of the event notification etc.
  • Added a couple more demo programs; one showing how to use the event-handling procedures etc. (A translation of a PureDispHelper demo.)
The help manual has been adjusted accordingly.

See the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

For COMate_WrapCOMObject(); do you still need to supply the CLSID and IID also, like in a data section, in the code?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

SFSxOI wrote:For COMate_WrapCOMObject(); do you still need to supply the CLSID and IID also, like in a data section, in the code?
Nope, no GUID's required, just provide an interface pointer. The idea is that you may have obtained an interface pointer from some operation; e.g. CoCreateInstance_() and wish to quickly call some method without going through the vTable etc. In this case you can attempt to wrap it up in a COMateObject and call the method using COMate automation etc.

This function is really intended for event-handlers where some event may pass a parameter (or two!) in the form of some COM interface or other. You can then use the COMate_WrapCOMObject() function to wrap this new object into a convenient COMateObject so that you can call it's dispinterface methods directly without having to worry about the COM interface's vtable etc. It is really just for convenience.

I know this differs from the GetObjectProperty() method of the COMate class where I automatically wrap up any iDispatch interfaces returned in the form of a COMateObject for convenience (thus avoiding the need for COMate_WrapCOMObject())), but I decided against doing this with event parameters because any objects passed in the form of an event parameter needs the client application to use it's Release() method anyhow. Because of this I figured that converting any event-objects to COMateObjects was best done manually in these cases.

**EDIT : bug!!! Your post led me to a little bug in the COMate_WrapCOMObject() function! :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update - version 1.1.3. 9th Sept. 2008.
Bug fixed with the COMate_WrapCOMObject() function.

See the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Hello srod,

i have a curious problem. I want to create a TypeLibInfo-Object
(TlbInf32.dll). The DLL ist registered.

But COMate_CreateObject() returns 0 and
COMate_GetLastErrorDescription() says everything is OK:

Code: Select all

TLITypeLibInfo.COMateObject

TLITypeLibInfo = COMate_CreateObject( "TLI.TypeLibInfo" )

If TLITypeLibInfo = 0
  If COMate_RegisterCOMServer("C:\WINDOWS\system32\TlbInf32.dll") = #S_OK
    blnRegister = #True
    TLITypeLibInfo = COMate_CreateObject( "TLI.TypeLibInfo" )
  EndIf
EndIf

Debug COMate_GetLastErrorDescription() ; -> Okay

Debug TLITypeLibInfo ; -> 0 
In VB6 there is no problem:

Code: Select all

Dim tliTypeLibInfo As TypeLibInfo
Set tliTypeLibInfo = New TypeLibInfo ' works
TIA & Greetings ... Kiffi
Hygge
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

Post by glops »

How do you install COMate ?
When I run even a simple example , I have always
"Line 17 : Structure not found: i" as an error message, in include COMate_Residents.pbi

I don't know how you can run samples....
Post Reply