Announcement

Collapse
No announcement yet.

GPF in Excel COM app.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GPF in Excel COM app.

    What's wrong with this PBWin9 code? I'm running this on Windows XP with Excel 12. The include file was created by using PowerBASIC COM Browser. The program consistently GPF's when getting to the following code line:

    Code:
    oExcelRange.FormulaR1C1(0) = vVnt
    Am I doing something wrong or is something not functioning correctly?

    If I run the same code on Windows Vista with Excel 8 and a properly updated include file, I get an error 99 (Object Error) on the following code line:

    Code:
    oExcelApp.Visible(0) = 1
    By the way, I'm specifically trying to use the direct interface.

    Code:
    #Compile Exe
    #Dim All
    
    #Include ".\Excel_PB9.inc"
    
    Function PBMain () As Long
        Dim oExcelApp       As Int__Application
        Dim oExcelWorkbook  As Int__Workbook
        Dim oExcelRange     As IRange
        Dim vVnt            As Variant
    
        oExcelApp = NewCom $PROGID_Excel_Application
        If IsFalse IsObject(oExcelApp) Then
            MsgBox "Cannot get object: oExcelApp"
            Exit Function
        End If
    
        oExcelApp.Visible(0) = 1
    
        oExcelWorkBook = oExcelApp.Workbooks.Add()
        If IsFalse IsObject(oExcelWorkbook) Or Err Then
            MsgBox("Excel could not open workbook.")
            GoTo Terminate
        End If
    
        oExcelRange = oExcelApp.ActiveCell
        If IsFalse IsObject(oExcelRange) Or Err Then
            MsgBox("Excel could not set range.")
            GoTo Terminate
        End If
        vVnt = "Sample Text"
        '-----------------------------
    MsgBox "Pause before setting text"
        'Here's where the GPF happens.
        oExcelRange.FormulaR1C1(0) = vVnt
    MsgBox "Pause after setting text"
        '-----------------------------
    
        oExcelWorkbook.Close
        oExcelApp.Quit
    
        MsgBox "Finished"
    
    
    Terminate:
        Let oExcelRange     = Nothing
        Let oExcelWorkbook  = Nothing
        Let oExcelApp       = Nothing
    End Function
    Thanks,
    Calvin

  • #2
    You can not use Excel with direct interface calls. Only a few interfaces will work properly.

    oExcelRange = oExcelApp.ActiveCell

    doesn't return a reference to the IRange interface, but to the Range dispatch interface, that can only be used with OBJECT CALL/GET...
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Thanks José.

      How do you determine what can use the direct interface and what cannot?

      Comment


      • #4
        If there are interfaces with virtual tables, you can call them using direct interface calls. But Excel is an oddity: it has a mix of dual interfaces, dispatch only interfaces and dispatchable interfaces, and the last ones can't be used with direct interface calls because any method or property returns a reference to them.

        In the case of the ActiveCell property, look at the declaration:

        Code:
        Property Get ActiveCell <305> () As [B]Range[/B]
        It returns a reference to the Range dispatch interface, not to the IRange interface.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment

        Working...
        X