Results 1 to 20 of 20

Thread: VB6 - Raise Events from late-bound Objects (bonus "cRegFree" class for ActiveX DLLs!)

Threaded View

  1. #8

    Thread Starter
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,652

    Talking Re: VB6 - How to Raise Events from late-bound objects (declared generically As Object

    Quote Originally Posted by xiaoyao View Post
    How to list all the parameter names and parameter types owned by the event, and do you need to return the value REF?
    You get the parameter types from the variant array of parameters. Each variant contains type information in the first two bytes (retrievable by the VarType function). As for the parameter names, they are not saved anywhere so you cannot retrieve them. VB6 does not allow named parameters for events, like this for example:
    Code:
    Public Event DummyEvent(sName As String)
    
    RaiseEvent DummyEvent(sName:="Disgruntled") ' You can't used named parameters when raising events (syntax error in IDE)
    Also it is not required to return the values of "ByRef" parameters but you lose functionality if you skip that part. For example you have no way to know if some parameters have been changed in the event procedure if you don't send them back to the caller. The new version (updated in the first post above) checks if the parameters have been changed before sending them back.

    Quote Originally Posted by xiaoyao View Post
    by activex dll,it's can list all events name,but in vb6 ide class1,only can list allmethod,i don't khnow why?
    Set objITypeInfo = objITypeLib.GetTypeInfoOfIID(EventSink.IID_Event) 'it's nothing why?
    I've already mentioned this in the code comments if you read them. Standard EXEs don't include a "TypeLib", so it's more complicated to retrieve function names (only works for "Public" methods of classes anyway). ActiveX projects (EXE, DLL and OCX) include their TypeLibs in the compiled file which makes it possible to retrieve the names of events.

    I have updated the ZIP file in the first post above to fix the bug that you found as well as another bug (when using events with array parameters). Also this new version includes a way to choose between raising NamedEvents with strong typed parameters as well as a GenericEvent with a variant array of parameters. The choice is up to the you.

Posting Permissions

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



Click Here to Expand Forum to Full Width