Results 1 to 7 of 7

Thread: Return Error info from ActiveX Dll to User Application

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    35

    Return Error info from ActiveX Dll to User Application

    I create ActiveX Dll to serve my own applications.
    What is the best way to return error from dll to app?

    My dll has the Dll_class and several support modules.
    And app has the App_class, which create the instance of Dll_Class with events.
    In App_module declared and created several instances of App_class for various purposes.

    Dll_class functions returns any values on success and 0(zero) if something goes wrong.
    However, cause this 0(zero) is noninformative, so I create in Dll_class a special function,
    that returns my own last error number and description, when App recieving 0(zero) call its.
    This Error values saved in class level variables and refreshed each time, when Dll_class function decide to return 0(zero).

    Maybe I invent an another bicycle, but there are best practices solutions for a long time already?..

    Solutions are existing of course, but, unfortunately, not in those places where I was intensively looking for it :)
    .
    Last edited by asbo; Jun 23rd, 2018 at 05:26 PM. Reason: Typo in Title

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Return Error info from ActeveX Dll to User Application

    Normally, I return 0 for success, and the error code for failure....someimes that's not always possible, in the cases like yours, the solution you have is what ends up working: create a GetError function that returns the last error encountered. There aren't too many other options. A third option i suppose would mean re-doing a lot of code, but you could have an output parameter (byref) in each method call that returns the error code or error message. But that's not a common solution.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    35

    Re: Return Error info from ActeveX Dll to User Application

    techgnome,
    thank you for support.

    * I return 0 for success ... that's not always possible
    Yeah. However, it's most suitable for me (in this case) to return 0 as error, but not as flag of no(zero)-errors was there.

    * you could have an output parameter (byref)
    I also looked this way, but me functions are overloaded by parameters already :)
    However, you accented on ByRef. Why?
    I, considering this option, meant ByVal ...
    .

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Return Error info from ActiveX Dll to User Application

    Because you want to change the value of the parameter in the sub so that the error code is there when it returns back out... if you pass byVal, it will "reset" on the way back out. That's because when you byVal, you pass the VALUE in, not a reference to the variable. In order to change a parameter and have it stick, you need to pass a reference to it using byRef.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    35

    Re: Return Error info from ActiveX Dll to User Application

    Yep... it's clear. Thank you.

    I just planned a different approach of how to clear error value - to avoid the followings:
    - possible mistakes in assignments of this value and
    - a lot of this assignments entries among code (in your ByRef case) and
    - many of ByRef passes through chain of modules,
    do it by calling special function (wo parameters at all) in class, that will reset error value in one place only with one only value.

    Thus, I will be free of the lookup on the entire code, if something goes wrong.
    .

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Return Error info from ActiveX Dll to User Application

    Would SetLastError apply to this scenario? If so, when your DLL returns zero to indicate a problem, it calls SetLastError before exiting. Then the calling object can query Err.LastDLLError to return the error number? I don't know if that will be overwritten by the return value of the DLL -- but easy enough to check.
    Last edited by LaVolpe; Jun 24th, 2018 at 09:32 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    35

    Re: Return Error info from ActiveX Dll to User Application

    LaVolpe,
    thank you for advice.

    Yes, I also considered this scheme too and even read some discussions of this technique like this. It seemed me somewhat difficult, if accounting of my skill :) However, I keep it in mind for future.
    .

Tags for this Thread

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