Article View: borland.public.cppbuilder.nativeapi
Article #14023In Hell (LoadLibrary)
From: David
Date: Fri, 05 Sep 2003 14:45
Date: Fri, 05 Sep 2003 14:45
103 lines
4309 bytes
4309 bytes
I have a program running on Windows2000. Tested it on Win98 and it works for me. Sent it to
a reviewer and it fails at LoadLibrary. The hell part is that checking the Windows error
message (GetLastError) shows "The operation completed successfully."!!!! AAARRRRRGGGGGGG!
Any ideas? Here is the revelant code.
THelpAbout::THelpAbout(int x, int y, int top, int left) :
WinBlankForm(NULL, x, y, top, left, //Should not affect loadDll
(WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW) &
~WS_SIZEBOX & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX),
bmpC(NULL) {
debug.textOutEnd("Creating Help About");
//The following dllWrapC is a private member declared:
// private: DLL_Wrap dllWrapC;
if (!dllWrapC.loadDll(gAppPath + "\\" + "GraphicStuff.dll", debug)) {
MessageBox(NULL, "Unable to load GraphicStuff.dll", "Message", MB_SYSTEMMODAL | MB_OK);
debug.textOutEnd("Unable to load GraphicStuff.dll");
return;
}
...
}
Where dllWrapC is defined (deleting codeguards):
class DebugOut; //Forward declaration
class DLL_Wrap {
private:
std::string dllNameC;
HINSTANCE libHandleC;
public:
DLL_Wrap();
DLL_Wrap(std::string const & str);
~DLL_Wrap();
bool loadDll(std::string const & str);
bool loadDll(std::string const & str, DebugOut & debug);
HINSTANCE libHandle() { return libHandleC; }
};
And revelant implementation:
DLL_Wrap::DLL_Wrap() : libHandleC(NULL) { }
bool DLL_Wrap::loadDll(std::string const & str, DebugOut & debug) {
debug.textOutEnd("Attempting to load DLL.");
if (libHandleC) {
debug.textOutEnd("Library handle exists - freeing it.");
FreeLibrary(libHandleC);
}
libHandleC = LoadLibrary(str.c_str());
if (!libHandleC) { //LIBRARY FAILED TO LOAD
debug.textOutEnd("Library not loaded. Following is Windows error msg:");
mu::showLastSysError(debug); //WINDOWS SAYS IT COMPLETED SUCCESSFULLY
}
else {
debug.textOutEnd("Library loaded correctly");
}
return libHandleC;
}
And the mu::showLastSysError is defined as:
void mu::showLastSysError(DebugOut & debug) {
char * buf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buf, 0, NULL);
debug.textOutEnd(buf);
LocalFree(buf);
}
And the textOutEnd is:
void DebugOut::textOutEnd(std::string const & str) {
ofstream out(outFileName.c_str(), ios::out | ios::app);
if (!out) {
msgBox("Unable to open output file.\nProgram may still function OK.");
return;
}
out << str << endl;
out.close();
return;
}
As I said, it worked on my test on Win98 but not the customers. But then Windows shows the
operation completing sucessfully on the customers machine. I do not have access to their
machine. Here is the log file output.
"Creating Help About
Attempting to load DLL.
Library not loaded. Following is Windows error msg:
The operation completed successfully.
Unable to load GraphicStuff.dll
Closing Help-About"
Any ideas?
Thanks,
David
Technical Details
Message-ID:
<3F58A195.5000802@anonymous_one.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,4ba25b2fed50d3aa,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-09-05 07:46:25 PST Message-ID: <3F58A195.5000802@anonymous_one.com> Date: Fri, 05 Sep 2003 09:45:41 -0500 From: David <david@anonymous_one.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: In Hell (LoadLibrary) Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 64.152.234.38 X-Trace: newsgroups.borland.com 1062773004 64.152.234.38 (5 Sep 2003 07:43:24 -0700) Lines: 104 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail