COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

ahhh...so you think maybe the monitor is not detected because the switcher is actually the device the OS is seeing and not the monitor?

That kind of makes sense in a way because the switcher would not be detected in the monitor class. (I don't think it would at least.)
Last edited by SFSxOI on Sat Sep 06, 2008 8:02 pm, edited 1 time in total.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Need help:

Can't pass an array to the method :(

VB CODE

Code: Select all

  Dim oSM, ODesk as Object 'root object from OOo API
  Dim oDoc as Object       'The document to be opened
  Dim OpenPar(2) As Object 'a Visual Basic array, with 3 elements

'Instanciate OOo : the first line is always required from Visual Basic for OOo
  Set oSM = CreateObject("com.sun.star.ServiceManager")
  Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")

'We call the MakePropertyValue function, defined just before, to access the structure
  Set OpenPar(0) = MakePropertyValue("ReadOnly", True)
  Set OpenPar(1) = MakePropertyValue("Password", "secret")
  Set OpenPar(2) = MakePropertyValue("Hidden", False)

'Now we can call the OOo loadComponentFromURL method, giving it as
'fourth argument the result of our precedent MakePropertyValue call    
  Set oDoc = oDesk.loadComponentFromURL("file:///c|test.sxw", "_blank", 0, OpenPar)
PB code (i want to pass an empty array)

Code: Select all

XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"

Define.COMateObject oSM, oDesk, oDoc

Dim Array.SAFEARRAY(0)

document.s = "file:///" + GetCurrentDirectory() + "test.odt"

oSM = COMate_CreateObject("com.sun.star.ServiceManager")

If oSM

oDesk = oSM\GetObjectProperty("createInstance('com.sun.star.frame.Desktop')")


If oDesk

  document.s = "file:///" + GetCurrentDirectory() + "test.ott"
  document.s=ReplaceString(document,"\","/")

oDoc = oDesk\invoke("loadComponentFromURL('"+document+"','_blank',0,"+Str(@Array())+")")
;oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+document+"','_blank',0,"+Str(@Array())+")")
Debug oDoc
Debug COMate_GetLastErrorDescription() 


EndIf

oDesk\Release()
oSM\Release()

EndIf
Old DispHelp code (works)

Code: Select all

Define ocurseur, mdoc, chaine.s, document.s
Define.l oSM, oDesk, oDoc, oSrch, oCursor, Hit

XIncludeFile "DispHelper_Include.pb"
XIncludeFile "VariantHelper_Include.pb"

Define.safearray *openpar
Define.variant openarray

V_ARRAY_DISP(openarray) = *openpar

dhToggleExceptions(#True)

oSM = dhCreateObject("com.sun.star.ServiceManager")
If oSM
  ;Creating instance of Desktop
  dhGetValue("%o", @oDesk, oSM, ".CreateInstance(%T)", @"com.sun.star.frame.Desktop")
  ;Opening a new writer Document
  document.s = "file:///" + GetCurrentDirectory() + "test.ott"
  document.s = ReplaceString(document, "\", "/")
  dhGetValue("%o", @oDoc, oDesk, ".loadComponentFromURL(%T,%T,%d,%v)", @document, @"_blank", 0, openarray)
  

  dhReleaseObject(oDoc)
  dhReleaseObject(oDesk)
  dhReleaseObject(oSM)
  
EndIf
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I read somewhere that some monitors will not report themselves to WMI - it wasn't put in quite these terms and I don't know where I saw this. The suggestion is though that the problem may just be the monitor itself. :)
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

It's a high quality monitor from CTX with Plug & Pray support.
Not a Discounter Monitor with flickering Screen, is only a very old Monitor
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

monitors with drivers that are fully WDDM compliant should be OK though. Both of my Samsug 245 BW 24 inch give up the info to wmi here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@Num3 : I've uploaded a test version of Comate.pbi here for you to try with the following code :

Code: Select all

XIncludeFile "COMate.pbi" 
XIncludeFile "VariantHelper_Include.pb" 


Define.COMateObject oSM, oDesk, oDoc 

Define.safearray *openpar 
Define.variant openarray 

V_ARRAY_DISP(openarray) = safearray 

oSM = COMate_CreateObject("com.sun.star.ServiceManager") 
If oSM 
  ;Creating instance of Desktop 
    oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
    If oDesk
      ;Opening a new writer Document 
        document.s = "file:///" + GetCurrentDirectory() + "test.ott" 
        document.s = ReplaceString(document, "\", "/") 
        oDoc = oDesk\GetObjectProperty("loadComponentFromURL('" + document + "', '_blank', 0, " + Str(openarray) + " as variant)")
      If oDoc
        oDoc\Release()
      EndIf
      oDesk\Release()    
    EndIf
  oSM\Release()
EndIf
I don't have open office with which to perform any tests on the code so it's down to you! It may take us a few attempts to get it working! :wink:

**EDIT : if this doesn't work then I am thinking there looks to be a problem with the VariantHelper include with the V_ARRAY_DISP macro. I think that Arg\ppdispVal should read Arg\parray; not that it will make much difference I guess because it is a structureunion anyhow! :wink:
Last edited by srod on Sat Sep 06, 2008 10:31 pm, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@Num3
All codes, incl. the new by srod doesn't work with OpenOffice 3, so i can't
test it. I think the code works only for OpenOffice 2.x
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@ts-soft, does my code above (with the test version of COMate) work with OO 2? I had overlooked variant type method parameters! :roll:
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

srod wrote:@ts-soft, does my code above (with the test version of COMate) work with OO 2? I had overlooked variant type method parameters! :roll:
As i say, i have no OO 2 to test, i have only OO 3 beta 2 installed. In OO 3
comes no object, so i think the name is another.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sorry, I misunderstood your last post! :)
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

srod wrote:does my code above (with the test version of COMate) work with OO 2?
Sorry srod, it does not work with OO 2.01.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Found the problem!
I was forgetting to convert the filename to an URL encoded string!
I also spelled the document extension wrong .ott instead of .odt !

Here's a working example, works with OpenOffice 2/3 and also with IBM Symphony (aka Open Office with less bugs ;) )

Code: Select all

XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"


Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile = ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strFile
ProcedureReturn strFile
EndProcedure


Define.COMateObject oSM, oDesk, oDoc

Define.safearray *openpar
Define.variant openarray

V_ARRAY_DISP(openarray) = safearray

oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
  ;Creating instance of Desktop
    oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
    If oDesk
      ;Opening a exisiting Document
        document.s = GetCurrentDirectory() + "test.odt"       
        oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+ConvertToUrl(document)+"', '_blank', 0, " + Str(openarray) + " as variant)")
        
        Debug COMate_GetLastErrorDescription() 
        
      If oDoc
        oDoc\Release()
      EndIf
      oDesk\Release()   
    EndIf
  oSM\Release()
EndIf 
Here's an example to open an empty document:

Code: Select all

XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"


Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile = ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strFile
ProcedureReturn strFile
EndProcedure


Define.COMateObject oSM, oDesk, oDoc

Define.safearray *openpar
Define.variant openarray

V_ARRAY_DISP(openarray) = safearray

oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
  ;Creating instance of Desktop
    oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
    If oDesk
      ;Opening a new writer Document    
        oDoc = oDesk\GetObjectProperty("loadComponentFromURL('private:factory/swriter', '_blank', 0, " + Str(openarray) + " as variant)")      
      If oDoc
        oDoc\Release()
      EndIf
      oDesk\Release()   
    EndIf
  oSM\Release()
EndIf 
Last edited by Num3 on Sun Sep 07, 2008 9:37 am, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@Num3 : it doesn't work when passing filenames?

Have just discovered that the whole COMate BYREF system is flawed and needs rewriting! DOH! Not that this should affect your Open Office code there.
I may look like a mule, but I'm not a complete ass.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

srod wrote:@Num3 : it doesn't work when passing filenames?

Have just discovered that the whole COMate BYREF system is flawed and needs rewriting! DOH! Not that this should affect your Open Office code there.
Sorry i had a bug and edited my post...
I got it working, check above!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Excellent! :)

Now to correct this damn BYREF business!
I may look like a mule, but I'm not a complete ass.
Post Reply