• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Create fail for window produced by OWL 2.5

I am unable to run an .exe outside of the Borland c++4.5
environment. I presume I need a dll or something for this windows executable to run by itself. Can you help?
0
keithdigi
Asked:
keithdigi
  • 2
1 Solution
 
AVaulinCommented:
Try use staticaly linked libraries in your application.
Good luck.
0
 
keithdigiAuthor Commented:
Can you explain what statically linked libraries are and where I can find reference materials on the net.
0
 
md041797Commented:
Compile and run this application and it will tell you which DLLs your exe needs.

This is from Windows Developer's Journal, August, 1995

Listing 2: module.h — Header file for module.c
#define E_NFILE   1 // cannot open executable file
#define E_NMODULE 2 // cannot find module
#define E_NMAGIC  3 // not an executable
#define E_OLDAPP  4 // not a Windows executable
#define E_CORRUPT 5 // corrupt executable image
 
typedef struct tagMODULE {
    char szName[9];     // module name
    char szFile[128];   // module file name
    BOOL fImported;     // module is imported
    struct tagMODULE *pNext;
} MODULE;
 
typedef MODULE FAR *LPMODULE;
typedef int (CALLBACK* MODENUMPROC)(LPMODULE, LPARAM);
typedef void (CALLBACK* MODERRPROC)(int, LPSTR);
 
BOOL    GetImportModules(LPMODULE *, LPSTR, MODERRPROC);
VOID    FreeModuleList(LPMODULE);
 
 
/* End of file */
 


Listing 1: module.c — Source code for resolving imported DLLs
// compile with STRICT defined and large memory model.
#include <windows.h>
#include <string.h>
#include <malloc.h>
#include <io.h>
#include <direct.h>
#include "module.h"
 
int     GetImportFileName(LPSTR, LPSTR, LPSTR, int);
BOOL    InModuleList(LPMODULE, LPSTR);
BOOL    AppendModuleList(LPMODULE *, LPSTR, LPSTR, BOOL);
 
#define EMAGIC      0x5A4D
 
typedef struct tagEXEHDR {
    WORD wSignature;  // executable signature
    WORD wExtraBytes; // number of bytes in last page
    WORD wPages;      // number of pages in file
    WORD wRelocItems; // number of entries in relocation table
    WORD wHeaderSize; // size of header, in paragraphs
    WORD wMinAlloc;   // minimum allocation
    WORD wMaxAlloc;   // maximum allocation
    WORD wInitSS;     // initial SS value
    WORD wInitSP;     // initial SP value
    WORD wCheckSum;   // checksum
    WORD wInitIP;     // initial IP value
    WORD wInitCS;     // initial CS value
    WORD wRelocTable; // offset to relocation table
    WORD wOverlay;    // overlay number
} EXEHDR;
 
#define NEMAGIC     0x454E
#define NEHDROFF    0x3C
 
typedef struct tagNEWEXEHDR {
    WORD wSignature;     // new executable signature
    BYTE bVersion;       // linker version number
    BYTE bRevision;      // linker revision number
    WORD wEntryTable;    // relative offset to entry table
    WORD wEntryTableSize;  // size of entry table
    DWORD dwCheckSum;    // CRC checksum of file
    WORD wFlags;         // flags
    WORD wAutoDS;        // automatic data segment
    WORD wHeapSize;      // size of local heap
    WORD wStackSize;     // size of stack
    WORD wInitIP;        // initial IP value
    WORD wInitCS;        // initial CS value
    WORD wInitSP;        // initial SP value
    WORD wInitSS;        // initial SS value
    WORD wSegmentTableSize; // segments in segment table
 
 

    WORD wModuleTableSize;  // entries in module table
    WORD wNonResNameTableSize; // non-resident name table size
    WORD wSegmentTable;  // offset to segment table
    WORD wResourceTable; // offset to resource table
    WORD wResNameTable;  // offset to resident name table
    WORD wModuleTable;   // offset to module ref. table
    WORD wImportTable;   // offset to import name table
    WORD wNonResNameTable; // offset to non-resident name table
    WORD wMovable;       // number of movable entry points
    WORD wAlignment;     // alignment shift for segment data
    WORD wResourceSeg;   // resource segment count
    BYTE bExeType;       // target operating system
    BYTE bOtherFlags;    // other EXE flags
    WORD wGangLoad;      // relative offset to gangload area
    WORD wGangLoadSize;  // size of gangload area
    WORD wMinSwapSize;   // minimum code swap size
    WORD wExpVersion;    // expected version number for Windows
} NEWEXEHDR;
 
#if defined(__BORLANDC__)
    #include <dir.h>
    #define _getcwd getcwd
    #define _access access
#elif defined(__WATCOMC__)
    #define _getcwd getcwd
#endif
 
BOOL GetImportModules(LPMODULE *ppModuleList,
                    LPSTR pszFileName, MODERRPROC ShowError)
{
    HFILE hf;
    EXEHDR oldhdr;
    NEWEXEHDR newhdr;
    WORD wNewExeOffset, wModOffset, wModules;
    BYTE cbNameLen;
    LONG lTablePos, lNamePos;
    char szModuleName[9], szModulePath[128];
    char szModuleFile[128];
    char *p;
 
    if ((hf = _lopen(pszFileName, READ)) == HFILE_ERROR) {
        ShowError(E_NFILE, pszFileName);
        return FALSE;
    }
 
    lstrcpyn(szModulePath, pszFileName,
        sizeof(szModulePath));
    if ((p = strrchr(szModulePath, '\\')) != NULL)
        *(p+1) = '\0';
 
    else {
        _getcwd(szModulePath, sizeof(szModulePath)-1);
        if (szModulePath[lstrlen(szModulePath)-1] != '\\')
            lstrcat(szModulePath, "\\");
    }
         
    // Read in the old-style executable header block;
 
 

    if (_lread(hf, &oldhdr, sizeof(EXEHDR)) !=
        sizeof(EXEHDR)) {
        _lclose(hf);
        ShowError(E_NMAGIC, pszFileName);
        return FALSE;
    }
 
    // Verify that this is an executable file
    if (oldhdr.wSignature != EMAGIC) {
        _lclose(hf);
        ShowError(E_NMAGIC, pszFileName);
        return FALSE;
    }
         
    // Verify that this is a Windows executable
    if (oldhdr.wRelocTable < 0x40) {
        _lclose(hf);
        ShowError(E_OLDAPP, pszFileName);
        return FALSE;
    }
 
    // Read the offset to the NE header block
    _llseek(hf, (LONG)NEHDROFF, 0);
    _lread(hf, &wNewExeOffset, sizeof(WORD));
     
    // Read in the NE header block
    _llseek(hf, (LONG)wNewExeOffset, 0);
    if (_lread(hf, &newhdr, sizeof(NEWEXEHDR)) !=
        sizeof(NEWEXEHDR)) {
        _lclose(hf);
        ShowError(E_CORRUPT, pszFileName);
        return FALSE;
    }
 
    // Check the NE signature
    if (newhdr.wSignature != NEMAGIC) {
        _lclose(hf);
        ShowError(E_CORRUPT, pszFileName);
        return FALSE;
    }
 
    // Get the module name for this executable
    _llseek(hf, (LONG)(wNewExeOffset+newhdr.wResNameTable), 0);
    _lread(hf, &cbNameLen, sizeof(BYTE));
    _lread(hf, szModuleName, (int)cbNameLen);
    szModuleName[cbNameLen] = '\0';
    AppendModuleList(ppModuleList, szModuleName,
                     pszFileName, FALSE);
 
    // Calculate the absolute offset of the module table
    lTablePos = (LONG)(wNewExeOffset + newhdr.wModuleTable);
 
    wModules = newhdr.wModuleTableSize;
    while (wModules > 0) {    
        // Seek to the next entry in the module table
        _llseek(hf, lTablePos, 0);
        _lread(hf, &wModOffset, sizeof(WORD));
 
        // Calculate offset to the module name
        lNamePos = (LONG)(wNewExeOffset +
            newhdr.wImportTable + wModOffset);
        _llseek(hf, lNamePos, 0);
 
        // Read module name
        _lread(hf, &cbNameLen, sizeof(BYTE));
 
 

        _lread(hf, szModuleName, (int)cbNameLen);
        szModuleName[cbNameLen] = '\0';
 
        // Check if module is in table and add if needed
        if (!InModuleList(*ppModuleList, szModuleName)) {
            if (!GetImportFileName(szModuleName, szModulePath,
                szModuleFile, sizeof(szModuleFile)))
                ShowError(E_NMODULE, szModuleName);
            else {
                if (AppendModuleList(ppModuleList,
                    szModuleName, szModuleFile, TRUE)) {
                    if (!GetImportModules(ppModuleList,
                                  szModuleFile, ShowError)) {
                        _lclose(hf);
                        return FALSE;
                    }
                }
            }
        }
        wModules--, lTablePos += sizeof(WORD);
    }
    _lclose(hf);
    return TRUE;
}
 
int GetImportFileName(LPSTR pszModuleName,
        LPSTR pszModulePath, LPSTR pszModuleFile,
 
        int cbNameLen)
{
    HMODULE hModule;
    OFSTRUCT of;
    char szBaseName[15];
     
    // Get module name from in-memory module table  
    if ((hModule = GetModuleHandle(pszModuleName)) != 0)
        return GetModuleFileName(hModule, pszModuleFile,
            cbNameLen);
 
    // Search for the module filename
    lstrcpy(szBaseName, pszModuleName);
    lstrcat(szBaseName, ".DLL");
    of.cBytes = sizeof(OFSTRUCT);
 
    if (OpenFile(szBaseName, &of, OF_EXIST|OF_SEARCH) !=
        HFILE_ERROR) {
        lstrcpyn(pszModuleFile, of.szPathName, cbNameLen);
        return lstrlen(pszModuleFile);
    } else {
        char szPathName[128];
        lstrcpy(szPathName, pszModulePath);
        lstrcat(szPathName, szBaseName);
        if (_access(szPathName, 0) != -1) {
            lstrcpyn(pszModuleFile, szPathName, cbNameLen);
            return lstrlen(pszModuleFile);
        }
    }
 
    return 0;
}
 
BOOL InModuleList(LPMODULE pModuleList, LPSTR pszModuleName)
{
    while (pModuleList) {
        if (!lstrcmp(pszModuleName, pModuleList->szName))
 
 

            return TRUE;
        pModuleList = pModuleList->pNext;
    }
    return FALSE;
}
 
BOOL AppendModuleList(LPMODULE *ppModuleList, LPSTR
    pszModuleName, LPSTR pszModuleFile, BOOL fFlag)
{
    LPMODULE pNewModule;
             
    pNewModule = (LPMODULE)malloc(sizeof(MODULE));
    if (!pNewModule)
        return FALSE;
     
    lstrcpyn(pNewModule->szName, pszModuleName, 9);
    lstrcpyn(pNewModule->szFile, pszModuleFile, 128);
    pNewModule->fImported = fFlag;
    pNewModule->pNext = (LPMODULE)NULL;
 
    if (!*ppModuleList)
        *ppModuleList = pNewModule;
    else {
        LPMODULE pLastModule = *ppModuleList;
        while (pLastModule->pNext)
            pLastModule = pLastModule->pNext;
        pLastModule->pNext = pNewModule;
        pLastModule = pNewModule;
    }
     
    return TRUE;
}
 
VOID FreeModuleList(LPMODULE pModuleList)
{
    LPMODULE pFree;
         
    while (pModuleList) {
        pFree = pModuleList;
        pModuleList = pModuleList->pNext;
        free(pFree);
    }
}
/* End of file */
 
 



0
 
md041797Commented:
Statically linked libraries are libs that are linked in when your  linker links.  You can set this option by right clicking on your exe in the project view, select Target Expert, select static.  What this does essentially is link the DLLs at link time instead of requiring you to supply the DLLs.  Also, set you PATH environment to your \LIB directory and the system will get your LIB from there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now