Jump to content
  • Advertisement

Archived

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

Laroche

HRESULT questions

This topic is 6080 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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!