c - 通过管道发送结构数组 : win32, C

标签 c windows pipe named-pipes

我正在尝试使用 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/

相关文章:

shell - hudson : "yes: standard output: Broken pipe"

c - libusb_get_device_descriptor() 始终返回 0。如何检测故障?

c - 将串行输入读取到 C 变量

c++ - 注册表 - 获取上次更改值(不是 key )的时间和 key 创建日期

windows - MinGW g++ : Multiple definition of vsnprintf when using to_string

linux - 读取一个文件,一个 block 一个 block

linux - 我们如何在linux中创建 'special'文件,例如/dev/random?

python - 如何构造解压缩以空字符结尾的字符串?

c++ - 乘以 float 的更快方法

c# - 如何使用 C# 或注册表控制文件夹选项