Ignore:
Timestamp:
Aug 13, 2006, 10:58:34 PM (19 years ago)
Author:
bird
Message:

Fixed that 'ing hook problem. ARG!!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CPMScreen.cpp

    r2763 r2764  
    691691}
    692692
    693 HMODULE
    694 CPMScreen::openHookLibrary(const char* name)
    695 {
    696         // load the hook library - try with qualified name first.
    697         HMODULE hmod = NULLHANDLE;
    698     APIRET rc = ERROR_FILE_NOT_FOUND;
    699     char szFullName[CCHMAXPATH + 10];
    700     if (!_execname(szFullName, CCHMAXPATH)) {
    701         char *psz = strrchr(szFullName, '\\');
     693/**
     694 * Gets the path to the directory with the executable.
     695 * Has trailing slash.
     696 *
     697 * @returns pszBuf.
     698 * @returns NULL on buffer overflow.
     699 * @param   pszBuf      Where to store the path.
     700 * @param   cchBuf      The buffer size.
     701 */
     702static char *
     703getExecDir(char *pszBuf, size_t cchBuf)
     704{
     705    char *psz = NULL;
     706    if (!_execname(pszBuf,cchBuf)) {
     707        char *psz = strrchr(pszBuf, '\\');
    702708        if (!psz || strrchr(psz, '/')) {
    703709            psz = strrchr(psz, '/');
    704710        }
    705711        if (psz) {
    706             strcat(strcpy(psz + 1, name), ".DLL");
     712            psz[1] = '\0';
     713            return pszBuf;
    707714        }
    708             rc = DosLoadModule(NULL, 0, (PCSZ)szFullName, &hmod);
    709715    }
    710 
    711     // if that failed, try with the bare name.
    712     if (rc != NO_ERROR) {
    713             rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
    714     } else {
    715         name = szFullName;
     716    return NULL;
     717}
     718
     719HMODULE
     720CPMScreen::openHookLibrary(const char* name)
     721{
     722    //
     723    // Load the hook dll as a global DLL.
     724    //
     725    // The kernel/PM will fuck up if it's loaded with a path (i.e. non global).
     726    // What happend was that the DLL wasn't actually loaded into the other
     727    // processes for some stupid reason, leading to nasty crashes and even
     728    // weirder behaviour.
     729    //
     730    char szPath[CCHMAXPATH + 10];
     731    char szCwd[CCHMAXPATH];
     732    if (    getcwd(szCwd, sizeof(szCwd)) == NULL
     733        ||  getExecDir(szPath, sizeof(szPath)) == NULL
     734        ||  chdir(szPath) != 0) {
     735                LOG((CLOG_ERR "can't get cwd or exec dir or failed to change path to the exec dir!"));
     736                throw XScreenOpenFailure();
    716737    }
     738        HMODULE hmod;
     739    APIRET rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
     740    chdir(szCwd);
    717741        if (rc != NO_ERROR) {
    718742                LOG((CLOG_ERR "Failed to load hook library (%s), rc=%d ", name, rc));
     
    720744        }
    721745
    722         // look up functions
     746        // resolve the functions
    723747        if (    (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_fakeMsg",       (PPFN)&m_fakeMsg )) != NO_ERROR
    724748        ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setSides",      (PPFN)&m_setSides)) != NO_ERROR
Note: See TracChangeset for help on using the changeset viewer.