473,800 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Underdstanding HRESULT in DotNET

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
11 5942
"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
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

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******** ******@TK2MSFTN GP04.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
"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
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******** *****@TK2MSFTNG P04.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
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******** ******@TK2MSFTN GP05.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******** ******@TK2MSFTN GP04.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
"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.R esult.
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.Maxvalu e:

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

You could use the Bitconverter instead:

i = BitConverter.To Int32(BitConver ter.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

"Armin Zingler" <az*******@free net.dewrote in message
news:eE******** *****@TK2MSFTNG P02.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.R esult.
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 = MakeBelieveThis IsAnInteger(&HF FFFFFFF) '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.Maxvalu e:

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

You could use the Bitconverter instead:

i = BitConverter.To Int32(BitConver ter.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
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4014
by: Jon Maz | last post by:
Hi, I am trying to pass an array from an asp page (JScript) to a dotnet web service using the SOAP Toolkit 3.0. This is still at the Hello World stage, as you can see: WEB SERVICE METHOD public string AcceptArray(object parameters)
2
12897
by: Jay | last post by:
Hi All, If I'm wrong about posting this here please let me know the proper newsgroup. My system is W2K Pro, SP-4 + Rollback. The system crashed and I restored from my external backup. But 'dotnet' did not run due to this error message 'not installed'. So I used Add/Remove Programs and removed it. I then downloaded 'dotnet' again but the installation failed and I don't remember the
4
8588
by: lakshmi | last post by:
Hi We are rewriting a COM object in C#. The COM object returns HRESULT for invalid arguments, null values etc. The HRESULT is created using the MAKE_HRESULT macro in C++. 1.What is the C# equivalent of MAKE_HRESULT? 2.How do I return a HRESULT or an exception from my C# program that would indicate a FAILURE. Any help is appreciated. Thanks.
1
6344
by: Kimmo Laine | last post by:
Hi, we have a (unmanaged) ATL COM server, which implements two interface: ITestInterface1 and ITestInterface2. Both of these interfaces also support the ISupportErrorInfo-interface. Interface implementation is divided into two class: CTestInterface2, which implements the ITestInterfac2, and CTestInterface1, which implements ITestInterface1 AND ITestInterface2.
2
5210
by: Tny | last post by:
All of a sudden I started getting this error message before my VB.Net app would start. Before this it was running fine. Any ideas on what the problem could be? Thanks, Tny -- Sent via .NET Newsgroups
6
3252
by: =?Utf-8?B?Um9i?= | last post by:
Hi, If I call my own DLL from Javascript, a HRESULT is returned. Javascript cannot cast this to an integer. Is there any other way of typecasting this returnvalue to integer, wihout using the exception method which is described everywhere ? Please note that I am unfamiliar with javascript, I am used to C/C++. My Javascript call looks like : var result;
3
15936
by: wundertier | last post by:
Hi, I'm accessing COM objects from C#.net. In case of error a COMException is thrown which includes the HRESULT. But how do I get the description for the HRESULT? The Message property of the COMException does not contain any useful information. Example (I've got a german OS only, so I don't know the exact english version of these texts): HRESULT is: 800706ba
4
23544
by: yogarajan | last post by:
The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E) Source Error: An unhandled...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.