Click here to Skip to main content
16,004,944 members
Home / Discussions / COM
   

COM

 
GeneralRe: Handling COM events from VB for Applications Pin
rwestgraham8-Apr-05 15:00
rwestgraham8-Apr-05 15:00 
QuestionHow to use non .NET DLLs in .NET environment? Pin
Khang Nguyen8-Apr-05 5:30
Khang Nguyen8-Apr-05 5:30 
AnswerRe: How to use non .NET DLLs in .NET environment? Pin
rwestgraham8-Apr-05 14:40
rwestgraham8-Apr-05 14:40 
GeneralRe: How to use non .NET DLLs in .NET environment? Pin
Anonymous9-Apr-05 10:40
Anonymous9-Apr-05 10:40 
GeneralWriting COM object for C++ and VB Pin
Anonymous6-Apr-05 1:07
Anonymous6-Apr-05 1:07 
GeneralRe: Writing COM object for C++ and VB Pin
rwestgraham6-Apr-05 9:15
rwestgraham6-Apr-05 9:15 
GeneralRe: Writing COM object for C++ and VB Pin
Anonymous8-Apr-05 4:27
Anonymous8-Apr-05 4:27 
GeneralRe: Writing COM object for C++ and VB Pin
rwestgraham8-Apr-05 10:40
rwestgraham8-Apr-05 10:40 
Anonymous wrote:
Can I tell if S_OK or S_FALSE was returned then? Is S_OK equal to 0 in VB? What type does it return a string or an integer? I tried it with an integer and it did not work or if it returns S_FALSE will it raise an exception in VB?

Sorry, it's been a long time since I looked at this stuff. I'll try to explain as much as I can remember.

1) Your attempt to return an integer failed because VB requires all COM calls to return an HRESULT.

2) You cannot ever get the original value of an HRESULT in VB because the runtime pre-processes it behind the scenes. You cannot tell if S_OK was returned or if S_FALSE was returned, because you can never get directly at the actual HRESULT returned.

3) Returning a S_FALSE will not raise an error in VB because S_FALSE is actually a success code, not an error code. The first thing VB does when it processes the HRESULT behind the scenes is strip out the low word and check it for a severity level. An S_ code is always considered successful based on the low word, so VB just discards the rest and keeps going. In order for an error to be raised in VB the severity level of the low word must be an error level. So if your method returns E_FAIL, VB will look at the low word of the HRESULT, see it is an error level severity and go from there.

4) What happens in VB if you return an E_ HRESULT depends on how you've written your COM component:

If you support rich error information:

Your COM object must first call SetErrorInfo and fill the EXCEPINFO parameters. (If you are using ATL you can just call "Error(...)" and it provides overloaded constructors that will do all the work for you).

Then your COM object returns an E_ level HRESULT.

VB catches the E_ severity code level and will query your COM object to see if it supports the ISupportErrorInfo interface. Since in this case you do, it will call GetErrorInfo to get the EXCEPINFO structure.

If you do not support rich error information:

Your COM object simply returns an E_ level HRESULT.

VB catches the E_ severity code level and will query your COM object to see if it supports the ISupportErrorInfo interface. Since in this case you don't, VB does not attemnpt to call GetErrorInfo.

Since rich error info is not supported, VB tries to process the high word of the E_ HRESULT and translate it into a VB friendly standard error and standard VB message.

For example, suppose VB calls a method on your COM object and the method returns E_OUTOFMEMORY. The VB runtime strips out the low word, sees it is an error, looks at the high word and maps the error to the standard VB "Error 7 Out of Memory".


Finally,

The only ways to return an actual value to VB if you do not want to raise an error is by a [retval] parameter or by a ByRef [in, out] parameter. Of course all COM calls are functions - they return HRESULTS. But here is how VB interprets COM mmethods:

COM:
HRESULT MySub([in] long mylong);

VB:
Sub MySub(ByVal mylong As Long)

---------------------------------

COM:
HRESULT MySubByRef([in, out] long mylong);

VB:
Sub MySubByRef(ByRef mylong As Long)

----------------------------------

COM:
HRESULT MyFunction([in] long mylong, [out, retval] bool* p_boolRetVal);

VB:
Function MyFunction(ByVal mylong As Long) As Boolean

In all cases you never can get access to the HRESULT values in VB.

Hope this helps ...

Robert
GeneralRe: Correction to the above Pin
rwestgraham8-Apr-05 11:47
rwestgraham8-Apr-05 11:47 
GeneralRe: Correction to the above Pin
Anonymous11-Apr-05 0:02
Anonymous11-Apr-05 0:02 
GeneralRe: Correction to the above Pin
rwestgraham11-Apr-05 9:53
rwestgraham11-Apr-05 9:53 
GeneralProblem using ATL Object in other ATL Server Pin
andreasf5-Apr-05 20:26
andreasf5-Apr-05 20:26 
GeneralIHTMLDocument2 mouse handler Pin
Kharfax5-Apr-05 2:07
Kharfax5-Apr-05 2:07 
GeneralOutlook object library and windows service.. Pin
Muhammad Irfan Azam4-Apr-05 19:41
Muhammad Irfan Azam4-Apr-05 19:41 
QuestionFlash ActiveX MFC Control. Secure? Pin
RobotIntestines4-Apr-05 19:00
RobotIntestines4-Apr-05 19:00 
QuestionDLL and EXE files? Pin
123dotnet4-Apr-05 18:45
123dotnet4-Apr-05 18:45 
Generallinking to office-help Pin
sampad_m4-Apr-05 7:55
sampad_m4-Apr-05 7:55 
GeneralRe: linking to office-help Pin
rwestgraham7-Apr-05 12:33
rwestgraham7-Apr-05 12:33 
GeneralRe: linking to office-help Pin
sampad_m13-Apr-05 23:19
sampad_m13-Apr-05 23:19 
GeneralControl the Systemtray Pin
Anonymous2-Apr-05 5:30
Anonymous2-Apr-05 5:30 
GeneralRe: Control the Systemtray Pin
Anonymous2-Apr-05 21:17
Anonymous2-Apr-05 21:17 
Questionhow to call a function like "HRESULT test([in]byte* aaa);" using VBScript Pin
samfromcn31-Mar-05 15:19
samfromcn31-Mar-05 15:19 
AnswerRe: how to call a function like "HRESULT test([in]byte* aaa);" using VBScript Pin
rwestgraham31-Mar-05 18:27
rwestgraham31-Mar-05 18:27 
GeneralCookie read/write in COM Pin
Member 172086231-Mar-05 6:44
Member 172086231-Mar-05 6:44 
GeneralRe: Cookie read/write in COM Pin
Mike Dimmick31-Mar-05 10:24
Mike Dimmick31-Mar-05 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.