Click to See Complete Forum and Search --> : Contradictory Error Reporting with GetLastError


pandy0
May 4th, 2007, 01:41 PM
When using GetEnhMetaFile(), I get a null return value even though I have a valid emf and the path is correct. I then called GetLastError() to find out why it returned null, and the error message it gave me was 0, which says that the operation completed successfully. The line of code that gives the null handle is:


if((hEMF = GetEnhMetaFile( (LPSTR)temp_name)) == 0)
{
DWORD result = GetLastError();
}


Why is GetEnhMetaFile() returning a null handle?

Skeeterbreath
May 4th, 2007, 02:36 PM
That is one wicked problem! I know that isn't much help, but you got me stumped on that one.

pandy0
May 4th, 2007, 02:47 PM
You are so not cool. You had me thinking I had a real reply LOL.

MikeAThon
May 4th, 2007, 04:50 PM
Is that your actual code? The GetLastError() function must be called immediately after the failed GetEnhMetaFile() call, or else there's a chance that some other function might reset the error. Your code sample does that exactly, so if that's your actual code then it's curious that GetEnhMetaFile() is giving a NULL handle.

If it's not your exact code, then try moving the call to GetLastError() directly beneath the call to GetEnhMetaFile().

Mike

pandy0
May 4th, 2007, 04:54 PM
Yes that is the exact code. I copied and pasted it from the project. We thought it was curious, too. It's got me stopped in my tracks.

MikeAThon
May 4th, 2007, 07:34 PM
You mentioned that temp_name is correct, but since you're performing a hard-cast of temp_name (to a LPSTR), is it possible that temp_name is actually a unicode string?

Mike

pandy0
May 7th, 2007, 11:20 AM
It's declared as a BYTE. I originally took out the LPSTR, and that did not fix it.