COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The system menu has been deactivated here.

Are you saying that Excel's system menu still works?

The normal Excel menu should work okay - just the system one which I have deactivated.
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 »

> Are you saying that Excel's system menu still works?
There is no normal systemmenu, but the menu (the ugly round thing) works.
You can close, open and so on!
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 »

Ahhh, never used Office 2007!!! Any idea how to disable that thing?
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 »

No idea :?

Privat, i use only openoffice, looks better :D
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
CNESM
User
User
Posts: 54
Joined: Sat Jun 21, 2003 11:15 pm
Contact:

Post by CNESM »

**EDIT : problem with the above code. Select a cell, move the window off screen and back again and then try to select other cells!!! Having trouble fixing this. If anyone can find a fix then that would be very useful! I'll keep searching...
The same effect with Office 2000 but only when one excel instance in the task manager still run. Close all hitten instance and try it again, then it works fine with office 2000 (i know, office 2000 is old, but old skool doesnt lose his positive charisma :-D)

http://mitglied.lycos.de/cnesm/e.GIF

Long way around to come to finish line, but this example is great. You are the best, scrod! :)

New Point 1.

Yesterday, i found some new interesting thing (maybe clother to the thing we had already see):

If you set the "SetEventHandler" to the Excel.application you can catch all internal excel events. For example:
NewWorkbook
WorkbookActivate
WindowActivate
WorkbookBeforeClose
WindowDeactivate
WorkbookDeactivate
...
Simple example:

Code: Select all

Procedure myEventCallback5(object.COMateObject, eventName.s, parameterCount)
Debug eventName
EndProcedure

objExcel=COMate_CreateObject("Excel.Application")
HRESULT=objExcel\SetEventHandler(#COMate_CatchAllEvents,@myEventCallback5()) 
Thats great! So you can better see, what excel does!

New Point 2.

Maybe i am little stupid but does COMate support threads? This simple thread example didn't work althrough the objExcel is still avaible in the thread procedure:

Code: Select all

XIncludeFile "C:\Desktop\COMate_Residents.pbi" 
XIncludeFile "C:\Desktop\COMate.pbi" 

Global objExcel.COMateObject

Procedure DeineProzedur(a)
  objExcel\SetProperty("Cells(2,1) = 'But this input is NOT successfull!'")
EndProcedure
 
objExcel=COMate_CreateObject("Excel.Application")
objExcel\SetProperty("Visible = #True")
objExcel\GetObjectProperty("Workbooks\Add")

objExcel\SetProperty("Cells(1,1) = 'This input is successfull!'")

thread=CreateThread(@DeineProzedur(),0)

MessageRequester("Information", "", #PB_MessageRequester_Ok)

objExcel\SetProperty("DisplayAlerts = #False")
objExcel\Invoke("Workbooks.Close")
objExcel\Invoke("Quit")
But a simple procedure works fine:

Code: Select all

XIncludeFile "C:\Desktop\COMate_Residents.pbi" 
XIncludeFile "C:\Desktop\COMate.pbi" 

Global objExcel.COMateObject

Procedure DeineProzedur(a)
  objExcel\SetProperty("Cells(2,1) = 'And with a simple procedure this input is successfull, too!'")
EndProcedure
 
objExcel=COMate_CreateObject("Excel.Application")
objExcel\SetProperty("Visible = #True")
objExcel\GetObjectProperty("Workbooks\Add")

objExcel\SetProperty("Cells(1,1) = 'This input is successfull!'")

DeineProzedur(1)

MessageRequester("Information", "", #PB_MessageRequester_Ok)


objExcel\SetProperty("DisplayAlerts = #False")
objExcel\Invoke("Workbooks.Close")
objExcel\Invoke("Quit")
Maybe i am too stupid to do that right :?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

CNESM wrote:
**EDIT : problem with the above code. Select a cell, move the window off screen and back again and then try to select other cells!!! Having trouble fixing this. If anyone can find a fix then that would be very useful! I'll keep searching...
The same effect with Office 2000 but only when one excel instance in the task manager still run. Close all hitten instance and try it again, then it works fine with office 2000 (i know, office 2000 is old, but old skool doesnt lose his positive charisma :-D)
?
+ 1 8)

For info, that's work fine, even if there are another instance of EXCEL 2000, XP PRO SP2 8)
OFFICE 2000 it's like XP PRO, perhaps a little old, but better, efficient and not a christmas tree like VISTA and OFFICE 2007 :?
ImageThe happiness is a road...
Not a destination
CNESM
User
User
Posts: 54
Joined: Sat Jun 21, 2003 11:15 pm
Contact:

Post by CNESM »

For info, that's work fine, even if there are another instance of EXCEL 2000, XP PRO SP2
OFFICE 2000 it's like XP PRO, perhaps a little old, but better, efficient and not a christmas tree like VISTA and OFFICE 2007
Yes, you say it. Vista is like big shining blink blink, but no diamont, more likey a cheap plastic stone :wink:

I don't talk from a normal running excel instance further from a iregular hidden running application thats only display in the task manager.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

New Point 2.

Maybe i am little stupid but does COMate support threads? This simple thread example didn't work althrough the objExcel is still avaible in the thread procedure:
This took some sorting out this did!!! :)

First thing you have to initialise COM on each thread.

Second, and more importantly, COMate uses a single threaded apartment model (which is not good for multi-threaded access to a single object instance!) I can get your code working when I adjust COMate to use a multi-threaded apartment model, but this causes problems for PB itself. See the following reply from Freak regarding this : http://www.purebasic.fr/english/viewtopic.php?t=36830

The point is that I cannot persist with this adjustment to COMate because of what it means for PB and so we must look elsewhere for a solution.

Basically, with the single-threaded apartment model, a thread cannot directly call methods on an object it did not create. The way around this is to bully COM into serialising such method calls and for us to 'marshall' our object pointers for use by different threads. Now COM handles the serialising (via a hidden window's message queue), we must handle the marshalling aspect through a couple of api function calls. Functions which don't fit that well into the COMate way of doing things I'm afraid!

To be honest, I am not 100% sure if I want to add this cross-thread marshalling to COMate? It appears simple enough, but how many people would require this as a serious addition to COMate?
Last edited by srod on Sat Mar 21, 2009 9:34 pm, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
CNESM
User
User
Posts: 54
Joined: Sat Jun 21, 2003 11:15 pm
Contact:

Post by CNESM »

Hi srod,

thanks that you take care about this point! The advantage must stay in reconcile to the expenditure of this problem. It doesn't make sense to change a function or add a new feature only to add a new feature, when you know what i mean :-). When this changes bring additionaly more trouble to PB then it will be better when you doesn't change the STA to MTA. Maybe its useful when you add this information to the help file of COMate, so the next user will not ask when he have the same stupid knowledge like me ;-D

I will handle this point by another way! Thanks scrod!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, as I say, changing to MTA is not possible because of the information imparted by Freak. What is possible is the marshalling of interface pointers between the different threads, but I will add this only if there is a real need. :)
I may look like a mule, but I'm not a complete ass.
CNESM
User
User
Posts: 54
Joined: Sat Jun 21, 2003 11:15 pm
Contact:

Post by CNESM »

This function would not be bad, i think, but no stress, scrod, with this ne function. Maybe the other users see it in a other way ...
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

If I have this:

Code: Select all

objPorts = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")")

(which doesn't work by the way)

This is the original function
C++

HRESULT Item(
  [in]   LONG portNumber,
  [in]   NET_FW_IP_PROTOCOL ipProtocol,
  [out]  INetFwOpenPort ** openPort
);

VBScript
Function Item( _
  ByVal  port, _
  ByVal ipProtocol _
)

Is there a better way to use this without the strings and just put the values in as val and not strings?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Only by using variants directly, but then that is even more long winded.

If it doesn't work then I would guess that there is something wrong with your code. What error does COMate report?
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 »

Its that method is not correct thing. I was concerned about adding that second parameter and its a correct parameter but I'm not sure if i added it correctly but i think i did. I may not be doing it correctly tho because i don't know if i have to build a collection first but it doesn't seem like i should need to. I just started on it this morning early about 4 AM so maybe its as simple as not enough coffee yet :)
Last edited by SFSxOI on Tue Mar 31, 2009 1:11 pm, 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 »

You mean "One or more arguments are invalid...." ?
I may look like a mule, but I'm not a complete ass.
Post Reply