🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13920

Still In Hell (LoadLibrary)

#13920
From: David
Date: Mon, 08 Sep 2003 23:39
110 lines
5713 bytes
Three days ago I posted my 'In Hell' thread.  I followed Bob's advice for obtaining more info 
(thanks Bob!).  Now I am totally lost.  Nothing makes sense.  In short, I'm using Window's 
LoadLibrary to dynamically load a DLL.  The DLL exists, but LoadLibrary is not loading it, 
and LoadLibrary is not reporting any error through GetLastError.  All I can do is to list the 
code and hopefully somebody may have an idea what is happening.

I do not have access to the computers my friends are trying to run the program on.  They have 
told me that they are running Windows98SE, with 256 meg ram, and they have given me the debug 
info a modified program of mine produced from the following code.  I have tested the program 
on Windows98SE with 512mb ram on my end, and it works flawlessly.  It also works on 
Windows2000.  One thing I will mention is that the program is compiled with the standard call 
calling convention.  I don't think that should make a difference, but....?????  If you see 
anything please post it.  Thanks.

The debugging output created by the modified program (given line numbers for ref):
    1 Opening MEdit
    2 Application path set to: C:\PROGRAM FILES\AUDIO\MEDIT
    3 Creating Help About
    4 Application path: C:\PROGRAM FILES\AUDIO\MEDIT
    5 Attempting to load DLL.
    6 DLL location: C:\PROGRAM FILES\AUDIO\MEDIT\GraphicStuff.dll
    7 FileExists == true
    8 Library not loaded.  Following is Windows error msg:
    9 The operation completed successfully.

    10 Unable to load GraphicStuff.dll  [yes - above is blank.  GetLastError must have \r\n]
    11 Closing Help-About


In unit with problems:
extern DebugOut * gDebug;  //Instantiated in main form

THelpAbout::THelpAbout(int x, int y, int top, int left) :
             WinBlankForm(NULL, x, y, top, left,  //Should not affect dllWrap...
                         (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW) &
                         ~WS_SIZEBOX & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX),
             debug(*gDebug),  //For convenience of not changing old code, and using .()
             bmpC(NULL) {

    debug.textOutEnd("Creating Help About");  //Line 3
    debug.textOut("Application path: "); debug.textOutEnd(gAppPath.c_str());  //Line 4
    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");  //Line 10
       return;
       }
    //rest snipped as problem is above
}

The appropriate portions of DLL_Wrap are the following:
DLL_Wrap::DLL_Wrap() : libHandleC(NULL) { }  //libHandleC is declared as
             //private: HINSTANCE libHandleC;

bool DLL_Wrap::loadDll(std::string const & str, DebugOut & debug) {
    debug.textOutEnd("Attempting to load DLL.");  //Line 5
    if (libHandleC) {
       debug.textOutEnd("Library handle exists - freeing it.");
       FreeLibrary(libHandleC);
       }
    debug.textOut("DLL location: "); debug.textOutEnd(str.c_str());  //Line 6
    libHandleC = LoadLibrary(str.c_str());
    if (mu::fileExists(str)) debug.textOutEnd("FileExists == true"); //non-VCL version of
                //FileExists, Line 7
    else debug.textOutEnd("FileExists == false");
    if (!libHandleC) {
       debug.textOutEnd("Library not loaded.  Following is Windows error msg:"); //Line 8
       mu::showLastSysError(debug);
       }
    else {
       debug.textOutEnd("Library loaded correctly");
       }
    return libHandleC;
}

And mu::showLastError():
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); //Line 9 (most perplexing to me - no Windows error message)
    LocalFree(buf);
}

and, for more completeness:
void DebugOut::textOutEnd(std::string const & str) {
    ofstream out(outFileName.c_str(), ios::out | ios::app);
    out << str << endl;
    out.close();
    return;
}

gDebugOut is created in the main window code, and goes:
#include "DebugOut.h"
DebugOut * gDebug;

//And in ctor of main window:
    {  char tempStr[2000];
       GetModuleFileName(NULL, tempStr, 2000);
       gAppPath = tempStr;
       gAppPath = gAppPath.substr(0, gAppPath.find_last_of("\\"));
       }

    gDebug = new DebugOut;
    gDebug->textOutEnd("Opening MEdit");  //Line 1
    gDebug->textOut("Application path set to: "); gDebug->textOutEnd(gAppPath.c_str()); //L2


Thanks,
David
Technical Details
Message-ID: <3F5D1326.2050005@anonymous_one.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,adeb054a441a66c4,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-09-08 16:39:57 PST
Message-ID: <3F5D1326.2050005@anonymous_one.com>
Date: Mon, 08 Sep 2003 18:39:18 -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: Still In Hell (LoadLibrary)
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.31.245.176
X-Trace: newsgroups.borland.com 1063064210 67.31.245.176 (8 Sep 2003 16:36:50 -0700)
Lines: 111
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail