On failure, the function returns 0. However, the last error is never set! I cannot get this function to work correctly. Tracing through the call in OllyDbg, there seems to be a problem on this line:
76C97692 E8 1ACBFFFF CALL imagehlp.ImageDirectoryEntryToData
76C97697 85C0 TEST EAX, EAX
76C97699 74 19 JE SHORT imagehlp.76C976B4
76C9769B 837D 08 48 CMP DWORD PTR SS:[EBP+8], 48 ; This line causes the function to fail!
76C9769F 75 13 JNZ SHORT imagehlp.76C976B4
On the marked line above, the value in memory is 0x40. After that comparison fails, EAX is set to 0 and the function returns. No SetLastError is ever called in the function, so I have no idea what the error is. I'm guessing there's an error with the size of the structure being passed in and the internal structure expected? I'll try to reverse the function more to figure that error out, but I still wanted to point out the last error never being set as per docs.
Edit: Microsoft Windows XP w/ Service Pack 2 [Version 5.1.2600]