- New to DLLs ... LoadLibrary returns "invalid handle"
- Posted by solivan01 on July 23rd, 2003
I'm hoping this is obvious to someone, but I'm not sure what is
happening since I'm so new to this.
I'm trying to use LoadLibrary to bring my DLL into the address space.
After LoadLibrary is called it returns a handle. But when I call
GetLastError() immediately after the LoadLibrary call, the error
returned is 6 - "invalid handle".
The handle value returned from LoadLibrary is: 0x00dc000 and when I
look at it in the watch window it expands to show an "unused" variable
with value 9460301.
Is this not a valid handle?
Are there any resources I could use to help me troubleshoot this issue
further? Are there some obvious things I should check in my code?
Thanks in advance for any insight!
Regards,
Sarah
- Posted by Sin on July 23rd, 2003
You should only use GetLastError() if LoadLibrary returns NULL as the
handle... Since you have a non-null handle, your call has succeeded and you
do not need to call GetLastError()... The value of GetLastError() might or
might not have been set by LoadLibrary(), but it is irrelevant since it
should not be called in the first place.
Alex.
- Posted by solivan01 on July 24th, 2003
Thanks, Alex. That does make sense. I guess the error could have
been thrown from anywhere. Since I did get a handle from LoadLibrary,
I will assume that things went fine there.
Immediately after my call to LoadLibrary I do a call to GetProcAddress
and pass it my handle and the name of my function in the recently
loaded DLL. GetProcAddress is returning a NULL, so something is not
right there. If I call GetLastError() after this one, I get error 127
"The specified procedure could not be found".
Before I was thinking that I had a bad handle and that using this
handle was causing the 127 error as well. If we assume that my handle
is good ... what should I look for that would be causing the 127
error. Maybe something is not quite right in my DLL? Obvious things
such as making sure my function is spelled correctly has been done.
I really appreciate your insight!
Sarah
- Posted by Elias Fotinis on July 24th, 2003
solivan01 wrote:
View the exported DLL procs with Depends.exe or a similar utility. The
proc name may be mangled (if DLL source is C++) or it may begin with an
underscore (if it's defined 'extern "C"').
- Posted by solivan01 on July 25th, 2003
I got it figured out now ... it had to do with the C++ name mangling
of functions. I created a .def file for my DLL and exported my
function name. It's working great now.
Thanks!