Solved

Err.Raise Returns Wrong Info from OCX

Posted on 1998-03-27
6
435 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

830 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