CEntityDLL::CEntityDLL(std::string filename)
{
handle = LoadLibrary(filename.c_str());
if (0 == handle)
{
char buf[255] = "Open Library Failure";
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),0,buf,
sizeof(buf),0);
throw new EntityDLLException(buf);
}
else
{
typedef entid (*GETID) ();
GETID getid = (GETID) GetProcAddress(handle, "regLibrary");
if (0 == getid)
{
char buf[255] = "Missing Symbol Failure";
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),0,buf,
sizeof(buf),0);
FreeLibrary(handle);
throw new EntityDLLException(buf);
}
else
{
libID = getid();
maker = (GETENT) GetProcAddress(handle, "getEntity");
if (0 == maker)
{
char buf[255] = "Missing Symbol Failure";
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),0,buf,
sizeof(buf),0);
FreeLibrary(handle);
throw new EntityDLLException(buf);
}
}
}
}
if means nothing!
Can anyone figure out what the hell is going on with this code?
It seems that those if statements aren't working. Two of the DLLs in the entity directory aren't entity DLLs (one is just a null file with a DLL extension), in order to test this out. So for the null file, handle = 0, but when I test it, execution passes to the else block, rather than the if. Same when the real but not entity DLL fails on GPA for getid. I haven't bothered testing GPAing maker, but I'd assume the same thing would happen.
It makes as much sense as the Chewbacca defense. Anyone able to figure out why VC7 hates me now?
have you stepped through with the debugger to make sure that handle = 0 when the file isn't loaded properly?
Quote:Original post by Nuget5555
have you stepped through with the debugger to make sure that handle = 0 when the file isn't loaded properly?
Of course I have.
EDIT: Odd thing is, when I broke just before the first if statement, and stepped through, it worked. At least until the throw, and then it said that the exception wasn't caught (never mind that the constructor is called in a try block with a catch for EntityDLLException).
Quote:Original post by v71
Asking for help without having any idea of how the code works, lowers the rating
So does being an unhelpful and critizising jerk.
Quote:Original post by coldacid
So does being an unhelpful and critizising jerk.
I checked that guys profile, it looks like he's been posting similar crap all over so don't take it personally. Anyway, it looks like he's been suspended for it [smile]
Not at all. Putting the literal (the 0) first, however, keeps handle from being assigned 0 if I forget one of the equal signs (0 = handle won't compile, but handle = 0 will).
Quote:Original post by grekster
(noob question) Does it make a difference that its 0 == handle and not handle == 0 ???
Not really, but the first method is preferred. Say you accidentally type = instead of ==. Using the first method, your compiler should report an error, as a constant like 0 can't be assigned a value. Using the second method the handle will be set to 0 and you won't get the behaviour you want. Plus, that error could be v. hard to track down.
EDIT: Heh, beaten to it :)
Quote:Original post by coldacidQuote:Original post by Nuget5555
have you stepped through with the debugger to make sure that handle = 0 when the file isn't loaded properly?
Of course I have.
EDIT: Odd thing is, when I broke just before the first if statement, and stepped through, it worked.
Could this be a threading issue?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement