COMate - control COM objects via automation - OBSOLETE!
> 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!
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

No idea
Privat, i use only openoffice, looks better

Privat, i use only openoffice, looks better

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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

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**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...

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:
Simple example:NewWorkbook
WorkbookActivate
WindowActivate
WorkbookBeforeClose
WindowDeactivate
WorkbookDeactivate
...
Code: Select all
Procedure myEventCallback5(object.COMateObject, eventName.s, parameterCount)
Debug eventName
EndProcedure
objExcel=COMate_CreateObject("Excel.Application")
HRESULT=objExcel\SetEventHandler(#COMate_CatchAllEvents,@myEventCallback5())
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")
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")

- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
+ 1CNESM wrote: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**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...)
?

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


Not a destination
Yes, you say it. Vista is like big shining blink blink, but no diamont, more likey a cheap plastic stoneFor 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

I don't talk from a normal running excel instance further from a iregular hidden running application thats only display in the task manager.
This took some sorting out this did!!!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:

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.
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!
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

I will handle this point by another way! Thanks scrod!
If I have this:
Is there a better way to use this without the strings and just put the values in as val and not strings?
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 _
)
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.