Page 1 of 1

Accessing 32-bit DLLs from 64-bit code

PostPosted: Sat Apr 28, 2018 6:39 am
by Antonio Linares
Thanks to Lailton for googling for it :-)

https://blog.mattmags.com/2007/06/30/accessing-32-bit-dlls-from-64-bit-code/

Basically the technique is to use IPC (Interprocess communication) between a 64 bits app and a 32 bits app:

The following IPC mechanisms are supported by Windows:

Clipboard
COM
Data Copy
DDE
File Mapping
Mailslots
Pipes
RPC
Windows Sockets


https://msdn.microsoft.com/en-us/library/aa365574.aspx?f=255&MSPPError=-2147217396

From all of them, the WM_COPYDATA seems the simplest way to go :-)

SendMessage( hWndToReceiveTheMessage, WM_COPYDATA, hWndSender, pPointerToACOPYDATASTRUCT structure ) --> value returned from hWndToReceiveTheMessage

Re: Accessing 32-bit DLLs from 64-bit code

PostPosted: Sat Apr 28, 2018 8:44 am
by Antonio Linares
https://stackoverflow.com/questions/1128150/win32-api-to-enumerate-dll-export-functions

https://msdn.microsoft.com/en-us/library/windows/desktop/ms679318(v=vs.85).aspx

Code: Select all  Expand view
#include <windows.h>
#include <stdio.h>
#include <dbghelp.h>

BOOL CALLBACK EnumSymProc(
    PSYMBOL_INFO pSymInfo,  
    ULONG SymbolSize,      
    PVOID UserContext)
{
    UNREFERENCED_PARAMETER(UserContext);
   
    printf("%08X %4u %s\n",
           pSymInfo->Address, SymbolSize, pSymInfo->Name);
    return TRUE;
}

void main()
{
    HANDLE hProcess = GetCurrentProcess();
    DWORD64 BaseOfDll;
    char *Mask = "*";
    BOOL status;

    status = SymInitialize(hProcess, NULL, FALSE);
    if (status == FALSE)
    {
        return;
    }
   
    BaseOfDll = SymLoadModuleEx(hProcess,
                                NULL,
                                "foo.dll",
                                NULL,
                                0,
                                0,
                                NULL,
                                0);
                               
    if (BaseOfDll == 0)
    {
        SymCleanup(hProcess);
        return;
    }                                
       
    if (SymEnumSymbols(hProcess,     // Process handle from SymInitialize.
                        BaseOfDll,   // Base address of module.
                        Mask,        // Name of symbols to match.
                        EnumSymProc, // Symbol handler procedure.
                        NULL))       // User context.
    {
        // SymEnumSymbols succeeded
    }
    else
    {
        // SymEnumSymbols failed
        printf("SymEnumSymbols failed: %d\n", GetLastError());
    }
   
    SymCleanup(hProcess);
}

Re: Accessing 32-bit DLLs from 64-bit code

PostPosted: Tue May 22, 2018 11:58 pm
by Lailton
Hi Antonio,

Thanks for it!

I will to test :D