Announcement

Collapse
No announcement yet.

Passing COM Object -> GPF

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

  • Passing COM Object -> GPF

    Hi! I explored the forums about this riddle, but I didn't get an real answer how to do this...

    Main Question:
    How to pass a COM Object (DISPATCH) to a function? In this code example it's just causing a GPF on the first call/get/let of the oDocument.
    In this case I use PB 8.03.

    Code:
    FUNCTION XML_Validate(BYVAL oDocument AS DISPATCH, lWithMSGBOX AS LONG) AS LONG
       LOCAL oErrDoc AS DISPATCH
       LOCAL sErrBuff AS STRING
    
       LOCAL sLine,sErrCode,sLinePos,sURL,sSource,sReason AS STRING
       LOCAL vRes AS VARIANT
       LOCAL vErrDoc AS VARIANT
    
       OBJECT GET oDocument.Validate() TO vErrDoc
    
       SET oErrDoc = vErrDoc
    
       IF ISFALSE ISOBJECT(oErrDoc) THEN
          MSGBOX "Object wasn't initialized!Error in '" + FUNCNAME$ + "'.",%MB_ICONERROR OR %MB_TASKMODAL,"Internal XML-Error"
          FUNCTION = %FALSE
          EXIT FUNCTION
       END IF
    
       'Error=
       OBJECT GET oErrDoc.ErrorCode TO vRes
       sErrCode = STR$(VARIANT#(vRes))
    
       IF ISFALSE lWithMSGBOX THEN
          FUNCTION = VAL(sErrCode)
          EXIT FUNCTION
       END IF
    
       'Error -> Error Handling.
       IF VAL(sErrCode) THEN
          OBJECT GET oErrDoc.URL TO vRes
          sURL = VARIANT$(vRes)
    
          OBJECT GET oErrDoc.LINE TO vRes
          sLine = STR$(VARIANT#(vRes))
    
          OBJECT GET oErrDoc.SRCTEXT TO vRes
          sSource = VARIANT$(vRes)
    
          OBJECT GET oErrDoc.REASON TO vRes
          sReason = VARIANT$(vRes)
    
          OBJECT GET oErrDoc.LINEPOS TO vRes
          sLinePos = STR$(VARIANT#(vRes))
    
          sErrBuff = "The XML-error " + sErrCode + " happend, while parsing '" + sURL + "'." + $CRLF+_
                     "Line" + sLine + ",Collumn " + sLinePos + "." + $CRLF + $CRLF + _
                     sReason
    
          MSGBOX sErrBuff,%MB_TASKMODAL OR %MB_ICONERROR, "XML-error while revalidating the document."
          FUNCTION = VAL(sErrCode)
       ELSE
          'Everything OK
          FUNCTION = %TRUE
       END IF
    END FUNCTION
    Best regards,
    Marc Giesmann
    Last edited by Marc Giesmann; 12 Nov 2008, 02:26 AM. Reason: PB version added

  • #2
    Set the dispatch in a variant, pass the variant, set it to a local dispatch var again.
    hellobasic

    Comment


    • #3
      Is there no other way- something like dimming the DISPATCH variables as Msxml2DOMDocument40
      before passing to the function or something like that?

      I remember that all this worked fine in some strange way, one or two years ago without the whole variant-converting stuff. I didn't change anything in my XML include since then, but now the same code is forcing GPFs.

      Confusing

      Maybe I used it another way like, but I don't have the sourcecode anymore where I used it. Only this include left from that time.

      Thanks for replying Edwin, I'll convert every function to something like a VARIANT- wrapper.

      Best regards,
      Marc Giesmann

      Comment


      • #4
        Byval ?

        I don't seem to recall ever having trouble with this with either 8 or 9. I see you have a Byval over-ride in front of the DISPATCH variable. Does this same problem occur with a default Byref pass?
        Fred
        "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

        Comment


        • #5
          Fred,
          thanks for having some thoughts about my problem.

          To answer your question: Yes =/
          BYREF,BYVAL all the same.

          Like I said: Very strange...

          Comment


          • #6
            Afaik passing a dispatch object var is prohibited?
            I never pass them directly.

            I often pass them via a macro which passes the varptr() and set a local dispatch var again.
            A dispatch var is a 'simple' dword in fact.
            hellobasic

            Comment

            Working...
            X