FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Utilities / Utilidades Accessing 32-bit DLLs from 64-bit code
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Accessing 32-bit DLLs from 64-bit code
Posted: Sat Apr 28, 2018 06:39 AM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Accessing 32-bit DLLs from 64-bit code
Posted: Sat Apr 28, 2018 08:44 AM
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 (fw): Select all Collapse
#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);
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: Accessing 32-bit DLLs from 64-bit code
Posted: Tue May 22, 2018 11:58 PM

Hi Antonio,

Thanks for it!

I will to test :D

Regards,

Lailton Fernando Mariano

Continue the discussion