我正在尝试使用 win32 中的管道从一个应用程序发送一个 *var,它实际上是一个 4 槽数组,从一个应用程序到另一个应用程序。我怎样才能正确地做到这一点?
据我所知,我的做法是正确的:
//sending like this:
if (!WriteFile(hPipeWriteGhosts[i],Ghosts, (DWORD) sizeof(map)*4, &n, NULL))
{
printf("[ERROR] Writing in the pipe... (WriteFile)\n");
exit(1);
}
//receiving like this
ret = ReadFile(HReadSPipe, Ghosts, sizeof(map)*4, &n, NULL); // Lê até ao numero de bytes for zero (pipe fechado) pk o cliente escreveu fim e n escreveu mais nada
if (!ret || !n)
MessageBox(hDlgGlobal, str, "Error", MB_YESNO | MB_ICONINFORMATION); // But in fact it shows me this all the time.
我怎样才能正确地做到这一点?
提前致谢。
最佳答案
好的,您的问题是您正在跨进程边界移动句柄和指针。您的map
包含一个char *
和一个HBITMAP
。您传输 char * 值,但不传输它指向的数据。您传输位图的句柄,但不是实际的位图。
关于c - 通过管道发送结构数组 : win32, C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10903838/