Solved

Err.Raise Returns Wrong Info from OCX

Posted on 1998-03-27
6
433 Views
Last Modified: 2008-02-01
We created a DCOM32.OCX.  We created a function called DCOM321.ErrorNumber as a temp for now, but we want to put the Err.Raise within it.  That way you can catch the error as a normal error at Client end.  When we try to connect to the remote server we can get server error's and then send them back to the Client EXE.  

One error being -2147221005 meaning cannot connect to server.

In the OCX we have something like this..
lr = functionname(parms)
msgbox lr            '  hr at this time is -2147221005
if hr <> 0 then
   Err.Number = lr
   Err.Raise lr + 27
   exit sub
endif

But the client EXE received -2147220978

Then we tried:

if lr <> 0 then
   lr = lr - 27
   Err.Number = lr
   Err.Raise lr + 27
   exit sub
endif

Then Client EXE received 429

The only way we can get this to work is at the client end we did this:
    msgbox Err.Description,,"Error: " & Err.Number - 27
That STINKS!

Help, on Raise, tells us to use the vbObjectError + 27 before it will work
properly.

Why must we add 27 to the ErrorObject?  
When we remove the + 27 then 429 is
sent back to the client EXE.
Because of this we can not get the error we want returned.
 
Any help would be Great!
0
Comment
Question by:Chizl
  • 3
  • 3
6 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 200 total points
ID: 1459919
Chizl, your error numbers should be between 0 and 65535.  Certain error numbers are reserved by VB.  You're first example shouldn't have worked according to the docs; however,

(-2147221005) + 27 = (-2147220978)

Is a true statement.  I would assume that since errors above 65535 or below 0 are not allowed, this behavior may not be reliable.

I suspect the 429 error you experienced in your second example was a runtime error 429 (ActiveX object can't create object) because of the improper use of the ERR object.

Pick a number like 20000 for example and raise the error as follows:

Const ErrNoConnect = 20000

Err.Raise vbObjectError + ErrNoConnect

0
 
LVL 4

Author Comment

by:Chizl
ID: 1459920
Thanx for the note, but that is already understood.  There is a way just maybe you and me don't know it..

-2147221005 is a Microsoft error that is returned from CLSIDFromString,
CLSIDFromProgID,
and CoCreateInstanceEx
API calls when connection to a remote server.   Using these calls disables VB debugging and we have figuared a way around it so ppl can debug again.  Miscrosoft knows of this problem and is fixed in VB6, but for now we are updating our DCOM32.ocx to return the error numbers that the API call returns to us.   http://www.karland.com/OurProducts/DCom32/ to see what we have so far.
0
 
LVL 4

Author Comment

by:Chizl
ID: 1459921
Oh, by the way as you can see we have returned -2147220978 so subtracting 27 from it should be possible.  We just didn't want the end user to have to do this.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 4

Author Comment

by:Chizl
ID: 1459922
-2147221005  == "Invalid class string" in MS terms..   If you have VC5 you can go into the BIN directory and launch ErrLookup
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1459923
Chizl, I didn't say it couldn't be done.  I have no idea what else may be affected if you go outside of the number range reserved for VB errors.  At best, my guess is you'll get unpredictable behavior (which might explain your experience).   Search help on "raise".
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1459924
Chizl, I didn't say it couldn't be done.  I have no idea what else may be affected if you go outside of the number range reserved for VB errors.  At best, my guess is you'll get unpredictable behavior (which might explain your experience).   Search help on "raise".
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question