• Advertisement

Archived

This topic is now archived and is closed to further replies.

HRESULT questions

This topic is 5903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What exactly is HRESULT, and how does it differ from LRESULT?More importantly, how can it be used effectively? I tried finding an answer in articles but cant seem to find a good definition. If anyone can help or post a link to somewhere i would be grateful.

Share this post


Link to post
Share on other sites
Advertisement
Both of them are typedefs used in windows'' API.

HRESULT = void*
LRESULT = long

Usually, an HRESULT represents a handle to a windows ''object'' of some kind and an LRESULT an error code or other numerical result.

As to how to use them effectively... well just use the appropriate type with the appropriate function.

Share this post


Link to post
Share on other sites
Just talking from memory( and not DDR ), isn´t an HRESULT a dword? . I don´t think it is a pointer type...

.-LAROCHE: They are costants used to enumerate errors(or absent of errors)

Share this post


Link to post
Share on other sites
Just talking from memory( and not DDR ), isn´t an HRESULT a dword? . I don´t think it is a pointer type...

.-LAROCHE: They are costants used to enumerate errors(or absent of errors)

What the hells!

Share this post


Link to post
Share on other sites
Here's some more info on how to use HRESULT. Say you have a function that has a HRESULT return type and the function is failing. Well, what you do is save the result and go through a switch or a series of if's (as in this case) to see what the failure was. Here's an example from some of my code:

HRESULT hRet = G.lpDDSWindow1->Blt(NULL, NULL, NULL,
DDBLT_COLORFILL|DDBLT_WAIT, &ddbltfx);

Here I do a blit. Say the Blt() doesn't work. I could test for some possible values like this:

if(hRet == DDERR_GENERIC )
error = 1;
if(hRet == DDERR_INVALIDCLIPLIST )
error = 2;
if(hRet == DDERR_INVALIDOBJECT )
error = 3;
if(hRet == DDERR_INVALIDPARAMS )
error = 4;
if(hRet == DDERR_INVALIDRECT )
error = 5;
if(hRet == DDERR_NOALPHAHW )
error = 6;
if(hRet == DDERR_NOBLTHW )
error = 7;
if(hRet == DDERR_NOCLIPLIST )
error = 8;
if(hRet == DDERR_NODDROPSHW )
error = 9;
if(hRet == DDERR_NOMIRRORHW )
error = 10;
if(hRet == DDERR_NORASTEROPHW )
error = 11;
if(hRet == DDERR_NOROTATIONHW )
error = 12;
if(hRet == DDERR_NOSTRETCHHW )
error = 13;
if(hRet == DDERR_NOZBUFFERHW )
error = 14;
if(hRet == DDERR_SURFACEBUSY )
error = 15;
if(hRet == DDERR_SURFACELOST )
error = 16;
if(hRet == DDERR_UNSUPPORTED )
error = 17;

error is declared as an int earlier. Then I could just print out error, and that would tell me which error I have. For more specifics, you can check the DX docs to tell you what each error means. Hope this helps.

--Vic--

Edited by - Roof Top Pew Wee on November 22, 2001 1:40:40 PM

Share this post


Link to post
Share on other sites
Ok, my mistake, MSDN says

HRESULT
A value returned from a function call to an interface, consisting of a severity code, context information, a facility code, and a status code that describes the result. For 16-bit Windows systems, the HRESULT is an opaque result handle defined to be zero for a successful return from a function, and nonzero if error or status information is to be returned. To convert an HRESULT into a more detailed SCODE (or return value), applications call GetSCode(). See SCODE.

LRESULT
Type used for return value of window procedures.

Share this post


Link to post
Share on other sites
Hmmm i understand it a bit more, but for the sake of clarity let me explain my problem:

I have 2 sourcefiles for my game, they are Windows.cpp and DirectX.cpp. I want to use a function in Windows.cpp called DirectDrawInit to create the object, etc. The DirectDrawInit is in the DirectX.cpp. Looking at the source-code for an example called "fullscreen demo" (a full-screen app for Direct Draw that came with the directx 8 SDK.) I noticed that they use HRESULT to call the function. I tried doing something similar with DirectDrawInit, but it does not work. I declared a prototype, but i get an error on the function call called "Undeclared Identifier". I dont understand why it would not work. Also, im trying to pass a handle to the window to the function, since in the function im attempting to set the coopertive level, which requires a handle to my window. If anyone can help, id be really grateful (i know its something silly im doing i just cant figure out what...)

Share this post


Link to post
Share on other sites
Most important question is do you know what you''re trying to do and why?

Do you have header files with the declarations of your functions/classes and are those files included in your source files?

Do you understand how to call functions, pass parameters to functions and obtain return values?

HRESULT is a Windows-defined type, meaning you can declare variables of it, functions of it and obtain results from functions of it:

HRESULT hr; // declare an HRESULT variable
HWND hwnd;
HINSTANCE hinst;
HRESULT InitInstance(HINSTANCE hinst_, HWND &hwnd_); // declare an hresult function
...
int WINAPI WinMain(...)
{
char buf[30];
hinst = hInstance;
hr = InitInstance(hinst, hwnd); // obtain an hresult return value
if FAILED(hr)
{
FormatMessage(...,..., GetLastError(), ..., &buf, ...,...);
MessageBox(..., ..., buf, ...);
}
}


I think your problem has nothing to do with HRESULTs themselves and more to do with the process of multi-file compilation and linking. Oh, and Windows.cpp and DirectX.cpp are very bad choices for source file names.

Share this post


Link to post
Share on other sites
While we''re on the topic of data types, can someone please fill me in on what WORD and DWORD are and when you would use them?

Share this post


Link to post
Share on other sites
WORD = size of a processor register (usually 32 bit)
DWORD = double word (64 bit)

Share this post


Link to post
Share on other sites
You might think so, but!

WORD: 16 bit unsigned integer
DWORD: 32 bit unsigned integer

Search for DWORD in the MSDN Library and you''ll find the definition. And a bunch of others too.

-Benny-

Share this post


Link to post
Share on other sites
Argh.. Am I cursed today ?

Well M$ is wrong, the definition of a word is the size of a processor register. So unless windows is still 16bit, a word should be 32 bits...

OH, that's why they're using DWORDs everywhere ...

Edited by - Fruny on November 22, 2001 6:35:10 PM

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
Argh.. Am I cursed today ?

No. The second time around you were working based on the true definitions of a word and a doubleword, but realize that those definitions are platform specific. Since the Windows API has existed since the 286, those definitions were originally 16-bit based but have had to carry over to Win32 for backwards compatibility.

Share this post


Link to post
Share on other sites
so where would you use WORD and DWORD? and do they store numbers or what?

Share this post


Link to post
Share on other sites
Anything you want to know about hresults are in msdn and winerror.h including the bitwise description of an hresult. basically they''re made of a facility code to tell where it came from, a severity bit to determine if its an error or not and if its an error how serious it is, and finally an error code.

If you want to make you''re own hresult use this

#define E_MYERROR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 512 or greater)

use FACILITY_ITF because thats the facility set aside for user error codes. and values less than 512 are reserved.


to simplify

Less than 0 = Error
Greater than 0 = success

Any more questions....consult WinError.h

Share this post


Link to post
Share on other sites
alright i understand now, and ill change my source names thanks to everyone who answered, it cleared things up a lot!

Share this post


Link to post
Share on other sites
quote:
Original post by Grugnorr
Just talking from memory( and not DDR ), isn´t an HRESULT a dword? . I don´t think it is a pointer type...

.-LAROCHE: They are costants used to enumerate errors(or absent of errors)

What the hells!


Actually, you''re right, HRESULT is typedef''d to a dword.



"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer

Share this post


Link to post
Share on other sites

  • Advertisement