Announcement

Collapse
No announcement yet.

PB Com Events (Straight from Help Files)

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

  • PB Com Events (Straight from Help Files)

    I am trying to get the hang of OOP with PB (and more to the point with other languages), and found what I was obviously overlooking in the docs (yes, I know, I know, :rtfm2: ) and obviously in my eagerness to get things running, I completely missed (or misunderstood) what was in front of me.

    Now that I am struggling with Events, I found straight from the docs (copy-pasted)
    PbComServer
    Code:
    #COMPILE DLL "EvServer.dll"
    
    $EvIFaceGuid = GUID$("{00000098-0000-0000-0000-000000000002}")
    $MyClassGuid = GUID$("{00000098-0000-0000-0000-000000000003}")
    $MyIFaceGuid = GUID$("{00000098-0000-0000-0000-000000000004}")
    
    INTERFACE STATUS $EvIFaceGuid AS EVENT
      INHERIT IUNKNOWN
      METHOD Done
    END INTERFACE
    
    CLASS MyClass $MyClassGuid AS COM
      INTERFACE MyMath $MyIFaceGuid
        INHERIT IUNKNOWN
        METHOD DoMath
          MSGBOX "Calculating..."   ' Do some math calculations here
          RAISEEVENT Status.Done()
        END METHOD
      END INTERFACE
    
      EVENT SOURCE STATUS
    
    END CLASS
    PbComClient.bas
    Code:
    #COMPILE EXE "EvClient.exe"
    
    $EvClassGuid = GUID$("{00000098-0000-0000-0000-000000000001}")
    $EvIFaceGuid = GUID$("{00000098-0000-0000-0000-000000000002}")
    $MyIFaceGuid = GUID$("{00000098-0000-0000-0000-000000000004}")
    
    CLASS EvClass $EvClassGuid AS EVENT
      INTERFACE STATUS $EvIFaceGuid AS EVENT
        INHERIT IUNKNOWN
        METHOD Done
          MSGBOX "Done!"
        END METHOD
      END INTERFACE
    END CLASS
    
    INTERFACE MyMath $MyIFaceGuid
      INHERIT IUNKNOWN
      METHOD DoMath
    END INTERFACE
    
    FUNCTION PBMAIN()
      DIM oMath AS MyMath
      DIM oStatus AS STATUS
    
      LET oMath = NEWCOM "MyClass"
      LET oStatus = CLASS "EvClass"
    
      EVENTS FROM oMath CALL oStatus
      oMath.DoMath
      EVENTS END oStatus
    END FUNCTION
    I won't be able to test under XP till tomorrow, but under vista it compiles fine, but running causes the ole crash about debugging, or finding an answer or report to M$

    Can anyone spot anything wrong??? I am so used to PB being more right than M$ is in documentation, that I find it hard to initially think a mistake, but more a mistake I made (which is usually the case, that when in doubt, its me that made it)

    Hopefully someone can spot what I can not, in a area that I am still trying to learn, so I do not know what to look for????
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    My guess is that you haven't registered EvServer.dll.

    Also, if you don't like GPFs, add error checking, i.e.

    LET oMath = NEWCOM "MyClass"
    IF ISNOTHING(oMath) THEN EXIT FUNCTION
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Thanx Jose,
      Being used to not needing dll's registered, I TOTALLLY forgot about regsvr32

      One thing I have noticed though, is regsvr32 does not like spaces in the file/folder path to the dll.
      (Yet another work around I will have to find the solution to, once I get events working)

      The sample works fine now that I registered the dll on XP, I will try Vista tonight.
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        You can use COM DLL's without registering them first, but you have to change the syntax you're using to LET oMath = NEWCOM "MyClass" LIB <path of the DLL>.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          You can use COM DLL's without registering them first, but you have to change the syntax you're using to LET oMath = NEWCOM "MyClass" LIB <path of the DLL>.
          Hmmm.. heck of a technique to not permit users of a redistributed product to rename files, huh?

          Would allow you to simply scan the user's disk for a named file if you suspect someone is using it without your permission.

          Not to mention, would definitely simplify updates and upgrades.
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Cliff,

            In the Source Code forum:

            http://www.powerbasic.com/support/pb...ad.php?t=38286

            See my post "A Non-com Compliant Dll" for sample DLL/.INC/.BAS source for an unregistered DLL and PB program working together. This approach will work with COM complaint and non-compliant DLLs. It uses the PB LET syntax Jose has noted:

            Code:
            LET oVertice = NEWCOM CLSID $CLSID_CVACALC LIB "CVACalc_Custom.DLL"
            Rick Angell

            Comment

            Working...
            X