Solved

Err.Raise Returns Wrong Info from OCX

Posted on 1998-03-27
6
431 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now