By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Underdstanding HRESULT in DotNET

P: n/a
I've been Googling and there is many many hits but I can't find what I want.

I've read at one time how DotNET treats HRESULT but can't find it now.

Does it return HRESULT unchanged or does it check it for error-return or
what?

Thanks for any help
Jan 31 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Academia" <ac************@a-znet.comschrieb
I've been Googling and there is many many hits but I can't find what
I want.

I've read at one time how DotNET treats HRESULT but can't find it
now.

Does it return HRESULT unchanged or does it check it for
error-return or what?

Does this help?

http://msdn2.microsoft.com/en-us/lib...s1(VS.80).aspx

Armin
Jan 31 '08 #2

P: n/a
On Jan 31, 4:10 pm, "Academia" <academiaNOS...@a-znet.comwrote:
I've been Googling and there is many many hits but I can't find what I want.

I've read at one time how DotNET treats HRESULT but can't find it now.

Does it return HRESULT unchanged or does it check it for error-return or
what?

Thanks for any help
Also you can check this Wiki:
http://en.wikipedia.org/wiki/HRESULT
Jan 31 '08 #3

P: n/a

I'm doing a SendMessage that returns an HRESULT.

Do I see the "raw" HRESULT of is the "s" field checked and an exception
thrown if "Fail" is indicated?
Thanks to both of you, the sites are very helpful.

"Academia" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
I've been Googling and there is many many hits but I can't find what I
want.

I've read at one time how DotNET treats HRESULT but can't find it now.

Does it return HRESULT unchanged or does it check it for error-return or
what?

Thanks for any help

>

Jan 31 '08 #4

P: n/a
"Academia" <ac************@a-znet.comschrieb:
I'm doing a SendMessage that returns an HRESULT.

Do I see the "raw" HRESULT of is the "s" field checked and an exception
thrown if "Fail" is indicated?
The exact meaning depends on the message you are sending. Also note that
the return type of 'SendMessage' is 'LRESULT', not 'HRESULT'. Thus the
return value of 'SendMessage' should be typed as 'IntPtr' because 'LRESULT'
is an alias for 'LONG_PTR', which is defined as follows:

\\\
#if defined(_WIN64)
typedef __int64 LONG_PTR;
#else
typedef long LONG_PTR;
#endif
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 31 '08 #5

P: n/a
I'm sure what I'm writing will not run on Win64 so why IntPtr.
I been using Integer since vb.NET didn't allow UInteger when I wrote the
definitions.
Almost all my usage of SendMessage returns a numerical value that fits into
a Integer so why use IntPtr and have to convert the return to Integer?
It's not clear in my mind but I think even if SendMessage returned a
negative value and I had defined the return value as Integer it would work
OK wouldn't it?
I don't know what would happen if it returned a negative value and I had
defined the return as UInteger.
Would CInt() or CType() convert that return to an Integer by just changing
types without doing anything to the bits?


Thanks
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:um*************@TK2MSFTNGP04.phx.gbl...
"Academia" <ac************@a-znet.comschrieb:
>I'm doing a SendMessage that returns an HRESULT.

Do I see the "raw" HRESULT of is the "s" field checked and an exception
thrown if "Fail" is indicated?

The exact meaning depends on the message you are sending. Also note that
the return type of 'SendMessage' is 'LRESULT', not 'HRESULT'. Thus the
return value of 'SendMessage' should be typed as 'IntPtr' because
'LRESULT' is an alias for 'LONG_PTR', which is defined as follows:

\\\
#if defined(_WIN64)
typedef __int64 LONG_PTR;
#else
typedef long LONG_PTR;
#endif
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 31 '08 #6

P: n/a
I had written the top part of the last note (below) before I went to the
sites and it must have been scrolled off the screen when I added the Thanks
and sent it. Actually Wikipedia was clear, except it said:

An opaque result handle defined to be zero for a successful return from a
function and nonzero if error or status information is returned.

Does the successful value have to be zero or can it have a nonzero value as
long as the "s" bit is zero

Why is it called a handle?

Thanks

"Academia" <ac************@a-znet.comwrote in message
news:Ox**************@TK2MSFTNGP05.phx.gbl...
>
I'm doing a SendMessage that returns an HRESULT.

Do I see the "raw" HRESULT of is the "s" field checked and an exception
thrown if "Fail" is indicated?
Thanks to both of you, the sites are very helpful.

"Academia" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
>I've been Googling and there is many many hits but I can't find what I
want.

I've read at one time how DotNET treats HRESULT but can't find it now.

Does it return HRESULT unchanged or does it check it for error-return or
what?

Thanks for any help


>>


Jan 31 '08 #7

P: n/a
"Academia" <ac************@a-znet.comschrieb
I'm sure what I'm writing will not run on Win64 so why IntPtr.
I been using Integer since vb.NET didn't allow UInteger when I wrote
the definitions.
Almost all my usage of SendMessage returns a numerical value that
fits into a Integer so why use IntPtr and have to convert the return
to Integer?

Well, IntPtr is the correct translation that works on Win32 and Win64.
Look at the type of the property System.Windows.Forms.Message.Result.
It's IntPtr, too.

If you know it will never run on Win64, you can choose Integer, too.
However, maybe one day you will wish you had chosen Intptr because you
will have to change Integer to Intpr everywhere. Though, that's up to
you to decide, of course.

It's not clear in my mind but I think even if
SendMessage returned a negative value and I had defined the return
value as Integer it would work OK wouldn't it?
Yep
I don't know what would happen if it returned a negative value and I
had defined the return as UInteger.
Nothing happens. It's just a matter of interpretation. The runtime can't
know whether the MSB is a sign or belongs to the value.
Would CInt() or CType() convert that return to an Integer by just
changing types without doing anything to the bits?
This fails because the value is Integer.Maxvalue:

Dim u As UInteger = &H80000000UI
Dim i As Integer = CInt(u)

You could use the Bitconverter instead:

i = BitConverter.ToInt32(BitConverter.GetBytes(u), 0)

- or leave it in an UInteger
If you need it later: ;-)
http://msdn2.microsoft.com/en-us/library/ms973190.aspx

Armin

Feb 1 '08 #8

P: n/a

"Armin Zingler" <az*******@freenet.dewrote in message
news:eE*************@TK2MSFTNGP02.phx.gbl...
"Academia" <ac************@a-znet.comschrieb
>I'm sure what I'm writing will not run on Win64 so why IntPtr.
I been using Integer since vb.NET didn't allow UInteger when I wrote
the definitions.
Almost all my usage of SendMessage returns a numerical value that
fits into a Integer so why use IntPtr and have to convert the return
to Integer?


Well, IntPtr is the correct translation that works on Win32 and Win64.
Look at the type of the property System.Windows.Forms.Message.Result.
It's IntPtr, too.

If you know it will never run on Win64, you can choose Integer, too.
However, maybe one day you will wish you had chosen Intptr because you
will have to change Integer to Intpr everywhere. Though, that's up to
you to decide, of course.
I going to try changing tomorrow when I'm bright (well at least brighter) -
see how many errors show up after I change the Declare statement. Might as
well do it right.

==========

What I was getting at below is suppose I had some bits in an UInteger and I
want to set the bits in a Integer to match them.

Dim i as Integer = MakeBelieveThisIsAnInteger(&HFFFFFFFF) 'Set i to -1
Is there a managed way to do this.

Thanks
>
>It's not clear in my mind but I think even if
SendMessage returned a negative value and I had defined the return
value as Integer it would work OK wouldn't it?

Yep
>I don't know what would happen if it returned a negative value and I
had defined the return as UInteger.

Nothing happens. It's just a matter of interpretation. The runtime can't
know whether the MSB is a sign or belongs to the value.
>Would CInt() or CType() convert that return to an Integer by just
changing types without doing anything to the bits?

This fails because the value is Integer.Maxvalue:

Dim u As UInteger = &H80000000UI
Dim i As Integer = CInt(u)

You could use the Bitconverter instead:

i = BitConverter.ToInt32(BitConverter.GetBytes(u), 0)

- or leave it in an UInteger
If you need it later: ;-)
http://msdn2.microsoft.com/en-us/library/ms973190.aspx

Armin

Feb 1 '08 #9

P: n/a
Suppose SendMessage ends like this:

, ByRef wParam As Integer, ByRef lParam As Integer) As IntPtr

and the call ends like this:

,X,Y) 'X and Y are Integer

Because SendMessage returns X and Y.

How can these lines be changed to use IntPrt?

Thanks


Feb 1 '08 #10

P: n/a
Create a Struct and define the return as that

Structure ShortPoint
Public X as Int16
Public Y as Int16
End Structure

Declare Function SendMessage Lib ............ As ShortPoint


"Academia" <ac************@a-znet.comwrote in message
news:eK****************@TK2MSFTNGP03.phx.gbl...
Suppose SendMessage ends like this:

, ByRef wParam As Integer, ByRef lParam As Integer) As IntPtr

and the call ends like this:

,X,Y) 'X and Y are Integer

Because SendMessage returns X and Y.

How can these lines be changed to use IntPrt?

Thanks

Feb 2 '08 #11

P: n/a
I think the point of this thread is that the parameters should be typed
IntPtr.
With ByVal I can simply do New IntPrt(X)
But with ByRef that would not work.

Thanks

"Bill McCarthy" <Bi**@NOSPAM.comwrote in message
news:52**********************************@microsof t.com...
Create a Struct and define the return as that

Structure ShortPoint
Public X as Int16
Public Y as Int16
End Structure

Declare Function SendMessage Lib ............ As ShortPoint


"Academia" <ac************@a-znet.comwrote in message
news:eK****************@TK2MSFTNGP03.phx.gbl...
>Suppose SendMessage ends like this:

, ByRef wParam As Integer, ByRef lParam As Integer) As IntPtr

and the call ends like this:

,X,Y) 'X and Y are Integer

Because SendMessage returns X and Y.

How can these lines be changed to use IntPrt?

Thanks


Feb 2 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.