Results 1 to 4 of 4

Thread: Exports and Executables

  1. #1

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Question Exports and Executables

    I know you can add exports to an executable... but what i want to know is how could you call them from a running executable? I want to use GetProcAddress() if possible, but in order to use GetProcAddress, you need the target HMODULE as the first parameter. So basically what i want to know is: How do you get the HMODULE of a running executable?

    thanks

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    GetModuleHandle
    The GetModuleHandle function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process.

    To avoid the race conditions described in the Remarks section, use the GetModuleHandleEx function.

    HMODULE GetModuleHandle(
    LPCTSTR lpModuleName // module name
    );
    Parameters
    lpModuleName
    [in] Pointer to a null-terminated string that contains the name of the module (either a .dll or .exe file). If the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.
    If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.

    Return Values
    If the function succeeds, the return value is a handle to the specified module.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.

    Remarks
    The returned handle is not global or inheritable. It cannot be duplicated or used by another process.

    The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. Therefore, use care when passing the handle to the FreeLibrary function, because doing so can cause a DLL module to be unmapped prematurely.

    This function must also be used carefully in a multithreaded application. There is no guarantee that the module handle remains valid between the time this function returns the handle and the time it is used by another function. For example, a thread might retrieve a module handle by calling GetModuleHandle. Before the thread uses the handle in another function, a second thread could free the module and the system could load another module, giving it the same handle as the module that was recently freed. The first thread would be left with a module handle that refers to a module different than the one intended.

    Windows 95/98/Me: GetModuleHandleW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    So basically what i want to do is:

    Pseudo code:

    void main(){
    CreateProcess("ExecutableWithExports.EXE");
    HMODULE hMod = GetModuleHandle("ExecutableWithExports.EXE");
    FARPROC targetProc = GetProcAddress(hMod, "theExport");
    (*targetProc)(para, met, ers);
    }

    ill give it a shot

  4. #4

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    well, its not working... heres what i tried:

    PHP Code:
    #include <windows.h>

    void main(){
        
    PROCESS_INFORMATION pi;
        
    STARTUPINFO si;
        
    memset(&si0x0sizeof(si));
        
    si.cb sizeof(si);
        
    CreateProcess("c:\\testDlg.exe"NULLNULLNULLTRUE0NULLNULL, &si, &pi);
        
    //HMODULE hMod = GetModuleHandle("testDlg.exe");
        //HMODULE hMod = GetModuleHandle("c:\\testDlg.exe");
        //HMODULE hMod = LoadLibrary("testDlg.exe");
        //HMODULE hMod = LoadLibrary("c:\\testDlg.exe");

    all 4 tries failed... any more suggestions?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width