#### Archived

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

# HRESULT questions

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

## 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 on other sites
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 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 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 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 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 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 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 variableHWND 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 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 on other sites
WORD = size of a processor register (usually 32 bit)
DWORD = double word (64 bit)

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009399
• ### Who's Online (See full list)

There are no registered users currently online

×