Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: COM_GetObject()

  1. #11
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: COM_GetObject()

    If excel is running it fails but if it is not running it opens excel makes a workbook and fills it and than askes if you want ot save and closes.

    Is this related http://support.microsoft.com/kb/266713.

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #12

    Re: COM_GetObject()

    Hi Abraxas,

    I do not think so because I don't use Active Template Library, in any case may be something related, I'll check again.

    If Excel is running you got a same or different handle?

    Thanks,
    Roberto
    http://www.thinbasic.com

  3. #13
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: COM_GetObject()

    thats odd. It crashes on my work computer (office 2000) whether excel is running or not but works on my home pc (office 2003) as previous post.

    on my work pc it reports different handles then crashes doesnt matter if excel is running or not.

    will test my home system after work and post results.

    hope that helps.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  4. #14

    Re: COM_GetObject()

    Hi,

    I downloaded the dll as well and dropped it in the thinbasic lib folder. On my computer both scripts return the error. Different handle as well as other errors and warnings such as on GetIDsOfNames(). It does not matter if Excel is running or not.

    I use Office2003 SP2 and a GenuineIntel processor.

    Added:

    What about http://support.microsoft.com/kb/238610/en-us and http://support.microsoft.com/kb/238975/en-us and http://support.microsoft.com/kb/196776/en-us
    Kind regards<br /><br />Marcel

  5. #15

    Re: COM_GetObject()

    Thanks, now I understand what happened, I returned IUnknown pointer instead of pointer to IDispatch interface for Automation.
    I'll fix the module ASAP (at least I hope).

    Regards,
    Roberto

    http://www.thinbasic.com

  6. #16

    Re: COM_GetObject()

    Roberto,

    Take your time, don't hurry.

    Kind regards

    Marcel
    Kind regards<br /><br />Marcel

  7. #17

    Re: COM_GetObject()

    Marcel,

    function COM_GetActiveObject() is now available.
    Also I added the COM_SetErrorBehavior() and COM_GetErrorBehavior() in order to manage the behavior that the script has to follow in case of an error.
    These are the behaviours:
    • %TB_ERROR_BEHAVIOR_DISPLAY_STOP display message and stop the script's execution (default)
    • %TB_ERROR_BEHAVIOR_DONT_DISPLAY don't display the error message
    • %TB_ERROR_BEHAVIOR_DONT_STOP don't stop the script's execution


    You can combine %TB_ERROR_BEHAVIOR_DONT_DISPLAY with %TB_ERROR_BEHAVIOR_DONT_STOP.

    Here is a script sample taht you can test with the attached module:

    [code=thinbasic]'----------------------------------------------------------------------------(')
    USES "COM"

    '----------------------------------------------------------------------------(')
    %NUMBER_OF_PARAMETERS = 3

    '----------------------------------------------------------------------------(')
    DIM pXlApp, pXlBooks, pXlSheet AS DWORD
    DIM vParam( %NUMBER_OF_PARAMETERS ), vRetVal AS VARIANT
    DIM hr, i, n AS LONG

    '----------------------------------------------------------------------------(')
    pXlApp = COM_GetActiveObject( "Excel.Application" )

    '----------------------------------------------------------------------------(')
    if pXlApp = 0 then
    msgbox 0, "Start a new Excel application"
    pXlApp = COM_CREATEOBJECT( "Excel.Application" )
    else
    msgbox 0, "Attach to existing Excel application"
    end if

    '----------------------------------------------------------------------------(')
    IF COM_SUCCEEDED( hr ) THEN
    FOR i = 1 TO %NUMBER_OF_PARAMETERS
    COM_VARIANTINIT( vParam( i ))
    NEXT
    vParam( 1 ) = 1
    IF COM_SUCCEEDED( COM_EXECUTE( pXlApp, "Visible", %TB_DISPATCH_PROPERTYPUT, 1, vParam( 1 ), 0 )) THEN
    MSGBOX 0, "Now Excel should be visible!"
    COM_VARIANTINIT( vRetVal )
    IF COM_SUCCEEDED( COM_EXECUTE( pXlApp, "Workbooks", %TB_DISPATCH_PROPERTYGET, 0, 0, vRetVal )) THEN
    pXlBooks = vRetVal
    IF COM_SUCCEEDED( COM_EXECUTE( pXlBooks, "Add", %TB_DISPATCH_METHOD, 0, 0, 0 )) THEN
    MSGBOX 0, "A new workbook should be added!"
    ELSE
    MSGBOX 0, "Add workbook fails"
    END IF
    IF COM_SUCCEEDED( COM_EXECUTE( pXlApp, "ActiveSheet", %TB_DISPATCH_PROPERTYGET, 0, 0, vRetVal )) THEN
    pXlSheet = vRetVal
    vParam( 1 ) = "ThinBASIC"
    IF COM_SUCCEEDED( COM_EXECUTE( pXlSheet, "Name", %TB_DISPATCH_PROPERTYPUT, 1, vParam( 1 ), 0 )) THEN
    MSGBOX 0, "ActiveSheet name should be changed!"
    FOR i = 1 TO 20
    FOR n = 1 TO 5
    vParam( 3 ) = i
    vParam( 2 ) = n
    vParam( 1 ) = "Hello"
    COM_EXECUTE( pXlSheet, "Cells", %TB_DISPATCH_PROPERTYPUT, %NUMBER_OF_PARAMETERS, vParam( 1 ), 0 )
    NEXT
    NEXT
    IF COM_SUCCEEDED( COM_EXECUTE( pXlApp, "Quit", %TB_DISPATCH_METHOD, 0, 0, 0 )) THEN
    MSGBOX 0, "Great!"
    END IF
    END IF
    END IF
    END IF
    ELSE
    MSGBOX 0, "Visible fails"
    END IF
    END IF

    '----------------------------------------------------------------------------(')
    IF ISFALSE( COM_SUCCEEDED( COM_RELEASE( pXlSheet ))) THEN
    MSGBOX 0, "ActiveSheet release fails"
    END IF

    '----------------------------------------------------------------------------(')
    IF ISFALSE( COM_SUCCEEDED( COM_RELEASE( pXlBooks ))) THEN
    MSGBOX 0, "Workbooks release fails"
    END IF

    '----------------------------------------------------------------------------(')
    IF ISFALSE( COM_SUCCEEDED( COM_RELEASE( pXlApp ))) THEN
    MSGBOX 0, "Excel application release fails"
    END IF
    [/code]

    Thank you very much and best regards,
    Roberto
    Attached Files Attached Files
    http://www.thinbasic.com

  8. #18

    Re: COM_GetObject()

    Hi Roberto,

    Thank you very much! I tested the dll and it works like a charm. I'll test it with MSWord as well. I see that I will have to overcome the same window activation I had in the other language but that is no problem at all. I have to look if thinBasic can activate a window by its name from the window list. If word has several documents open all the windows are named after the open documents.

    The best is that you now can manage the open ole_objects.&#160;

    Thank you very much!

    Kind regards

    Marcel
    Kind regards<br /><br />Marcel

  9. #19

    Re: COM_GetObject()

    Marcel,

    the function that you need already exist, it's hWnd = Win_FindByTitle(WindowTitle [, FindMethod])

    I'm sorry but I don't understand what you mean with
    open ole_objects
    do you mean Open Office?

    Ciao,
    Roberto


    http://www.thinbasic.com

  10. #20
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: COM_GetObject()

    Marcel,

    Win_FindByTitle is in UI module. Hope it is what you are searching.
    It can work with partial windows names, see help. But it will not work with child windows so if your MSWord uses different windows it will work fine other wise, old Word versions worked MDI. In this case Win_FindByTitle will not find child MDI windows.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 2 of 3 FirstFirst 123 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •