Saludos a todos.
En vista de una futura migración a FW64Bits, ¿Funciona Fast Report en 64 bits?
JoseAlvarez wrote:Saludos a todos.
En vista de una futura migración a FW64Bits, ¿Funciona Fast Report en 64 bits?
JoseAlvarez wrote:Saludos a todos.
En vista de una futura migración a FW64Bits, ¿Funciona Fast Report en 64 bits?
can you write an example of using IPC to use a 32 bits DLL from a 64 bits EXE on Windows ? Use C language
Certainly, I can provide an example of using Inter-Process Communication (IPC) to use a 32-bit DLL from a 64-bit EXE on Windows using C. This is a common scenario when dealing with legacy 32-bit DLLs that need to be used in modern 64-bit applications. We'll use named pipes for IPC in this example.
This example demonstrates how to use IPC with named pipes to communicate between a 64-bit EXE and a 32-bit EXE, which in turn loads and uses a 32-bit DLL. Here's a breakdown of the components:
64-bit EXE (main.c):
Creates a named pipe
Launches the 32-bit helper process
Reads the result from the pipe
32-bit EXE (helper32.c):
Loads the 32-bit DLL
Calls the function from the DLL
Sends the result back through the pipe
32-bit DLL (mylib32.c):
Contains a simple function that doubles its input
To use this example:
1. Compile the 32-bit DLL (mylib32.c) as a 32-bit DLL.
2. Compile the helper32.c as a 32-bit executable.
3. Compile the main.c as a 64-bit executable.
Make sure all three files are in the same directory when running the 64-bit EXE.
This approach allows you to indirectly use a 32-bit DLL from a 64-bit process by using a 32-bit helper process as an intermediary. The named pipe provides a simple way to pass data between the two processes.
// 64-bit EXE (main.c)
#include <windows.h>
#include <stdio.h>
#define PIPE_NAME "\\\\.\\pipe\\MyPipe"
#define BUFFER_SIZE 1024
int main() {
HANDLE hPipe;
char buffer[BUFFER_SIZE];
DWORD bytesRead;
// Create the named pipe
hPipe = CreateNamedPipe(
PIPE_NAME,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
1,
BUFFER_SIZE,
BUFFER_SIZE,
0,
NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
printf("CreateNamedPipe failed, error %d\n", GetLastError());
return 1;
}
// Start the 32-bit process
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi;
if (!CreateProcess("Helper32.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed, error %d\n", GetLastError());
CloseHandle(hPipe);
return 1;
}
// Connect to the client
if (!ConnectNamedPipe(hPipe, NULL)) {
printf("ConnectNamedPipe failed, error %d\n", GetLastError());
CloseHandle(hPipe);
return 1;
}
// Read the result from the 32-bit process
if (ReadFile(hPipe, buffer, BUFFER_SIZE, &bytesRead, NULL)) {
buffer[bytesRead] = '\0';
printf("Received from 32-bit process: %s\n", buffer);
} else {
printf("ReadFile failed, error %d\n", GetLastError());
}
// Clean up
CloseHandle(hPipe);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
// 32-bit EXE (helper32.c)
#include <windows.h>
#include <stdio.h>
#define PIPE_NAME "\\\\.\\pipe\\MyPipe"
#define BUFFER_SIZE 1024
// Function prototype for the DLL function
typedef int (*MYLIBFUNC)(int);
int main() {
HANDLE hPipe;
HMODULE hDll;
MYLIBFUNC MyLibFunc;
char buffer[BUFFER_SIZE];
DWORD bytesWritten;
// Load the 32-bit DLL
hDll = LoadLibrary("MyLib32.dll");
if (hDll == NULL) {
printf("LoadLibrary failed, error %d\n", GetLastError());
return 1;
}
// Get the function address
MyLibFunc = (MYLIBFUNC)GetProcAddress(hDll, "MyLibFunc");
if (MyLibFunc == NULL) {
printf("GetProcAddress failed, error %d\n", GetLastError());
FreeLibrary(hDll);
return 1;
}
// Call the function
int result = MyLibFunc(42);
// Connect to the named pipe
hPipe = CreateFile(
PIPE_NAME,
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
printf("CreateFile failed, error %d\n", GetLastError());
FreeLibrary(hDll);
return 1;
}
// Send the result back to the 64-bit process
sprintf(buffer, "Result from 32-bit DLL: %d", result);
if (!WriteFile(hPipe, buffer, strlen(buffer), &bytesWritten, NULL)) {
printf("WriteFile failed, error %d\n", GetLastError());
}
// Clean up
CloseHandle(hPipe);
FreeLibrary(hDll);
return 0;
}
// 32-bit DLL (mylib32.c)
#include <windows.h>
__declspec(dllexport) int MyLibFunc(int x) {
return x * 2;
}
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 17 guests