-
Jun 23rd, 2018, 04:02 PM
#1
Thread Starter
Member
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
-
Jun 23rd, 2018, 05:08 PM
#2
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
-
Jun 23rd, 2018, 05:41 PM
#3
Thread Starter
Member
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 ...
.
-
Jun 23rd, 2018, 05:56 PM
#4
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
-
Jun 24th, 2018, 05:15 AM
#5
Thread Starter
Member
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.
.
-
Jun 24th, 2018, 09:27 AM
#6
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.
-
Jun 24th, 2018, 01:58 PM
#7
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|