Bom dia pessoal!

Je rencontre un problème avec l'utilisation de la mémoire partagée entre processus. J'ai réussi à faire un code qui marche pour un array de char en mémoire partagée (et je lui passe une dimension MSG_SIZE = 31). Le code qui marche est le suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <windows.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
 
#define MSG_SIZE 31
#define BUFFER_SIZE 300
 
// THREAD PRIMARIA
int main()
{
 
	int i;
	int status;
	bool bStatus;
	DWORD dwThreadId;
	HANDLE hRAM;
	HANDLE hEventSent;
	HANDLE hEventRead;
	STARTUPINFO si;
	PROCESS_INFORMATION NewProcess;
	char Mensagem[] = "";
	char *Image;
	char PathBuf[BUFFER_SIZE];
	char PathBuf2[BUFFER_SIZE];
 
	SetConsoleTitle("CLP");
 
 
 
	hRAM= CreateFileMapping(
		(HANDLE)0xFFFFFFFF,
		NULL,
		PAGE_READWRITE,		// tipo de acesso
		0,					// dwMaximumSizeHigh
		MSG_SIZE,					// dwMaximumSizeLow
		"LISTA_CIRCULAR");			// Escolha o seu nome preferido
 
	Image= (char *)MapViewOfFile(
		hRAM,
		FILE_MAP_WRITE,		// Direitos de acesso: leitura e escrita
		0,					// dwOffsetHigh
		0,					// dwOffset Low
		MSG_SIZE);			// Número de bytes a serem mapeados
 
	// Cria evento com reset automático
	hEventSent= CreateEvent(NULL, FALSE, FALSE,"MsgAvailable");
 
	// Cria evento com reset automático
	hEventRead= CreateEvent(NULL, FALSE, FALSE,"MsgRead");
 
	// Cria processo servidor
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);	// Tamanho da estrutura em bytes
 
 
	if(!GetCurrentDirectory(BUFFER_SIZE, PathBuf))
	printf("GetCurrentDirectory() failed!\n");
 
	strcpy(PathBuf2, PathBuf);
	strcat(PathBuf,"\\CapturaMensagens\\Debug\\CapturaMensagens.exe");
	strcat(PathBuf2,"\\CapturaMensagens\\Debug");
 
	ZeroMemory(&si,sizeof(si));
	si.cb = sizeof(si);
 
	bStatus = CreateProcessA(PathBuf, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, PathBuf2, &si, &NewProcess);
	if (!bStatus) printf ("Erro na criacao do Processo! Codigo = %d\n", GetLastError());
 
 
	do {
		strcpy(Mensagem,"ESSAI");
 
		// Escreve na memória compartilhada
		strcpy(Image, Mensagem);	
		SetEvent(hEventSent);	// Avisa processo B
 
		// Espera que processo B leia a mensagem 
		WaitForSingleObject(hEventRead, INFINITE); 
		ResetEvent(hEventRead);
		printf("Buffer apos leitura/limpeza [deve ser NULL]= %s\n\n", Image);
	} while(TRUE);
 
	// Elimina mapeamento
	bStatus=UnmapViewOfFile(Image);
 
	CloseHandle(hRAM);
	CloseHandle(hEventSent);
	CloseHandle(hEventRead);
	CloseHandle(NewProcess.hProcess);
	CloseHandle(NewProcess.hThread);
}	// main

Jusque là, tout va bien. Mais ce n'était qu'une étape pour arriver à mon objectif, passer un array de char à 2 dimensions N*M ( char **Image; ), avec N=200 et M=31 (comme avant). J'ai tenté beaucoup de choses, jusqu'à écrire très salement, et je n'arrive vraiment pas à trouver comment modifier mon code qui fonctionne avec char *Image pour qu'il fonctionne avec char**.

Si vous avez une idée sur comment modifier CreateFileMapping et MapViewOfFile pour l'adapter à mon cas, je suis TRES intéressé! Dernière ligne droite de mon projet!

Obrigado antecipadamente gente!

Stochelo