小编Gal*_*Gal的帖子

如何使用命名管道在c ++ .dll和C#app之间发送消息?

我正在用C++编写注入的.dll,我想使用命名管道与C#app进行通信.

现在,我在C#app中使用内置的System.IO.Pipe .net类,我正在使用C++中的常规函数​​.

我没有太多的C++经验(阅读:这是我的第一个C++代码..),我在C#中经验丰富.

似乎与服务器和客户端的连接正常,唯一的问题是messaged没有被发送.我尝试将.dll作为服务器,C#app作为服务器,使管道方向InOut(双工)但似乎没有工作.

当我尝试将.dll发送到C#应用程序发送消息的服务器时,我使用的代码是这样的:

DWORD ServerCreate() // function to create the server and wait till it successfully creates it to return.
{
    hPipe = CreateNamedPipe(pipename,//The unique pipe name. This string must have the following form:  \\.\pipe\pipename
    PIPE_ACCESS_DUPLEX, 
    PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, //write and read and return right away
    PIPE_UNLIMITED_INSTANCES,//The maximum number of instances that can be created for this pipe
    4096 , // output time-out 
    4096 , // input time-out 
    0,//client time-out 
    NULL);

   if(hPipe== INVALID_HANDLE_VALUE)
   {
    return …
Run Code Online (Sandbox Code Playgroud)

c# c++ pipe

5
推荐指数
1
解决办法
1万
查看次数

malloc char*在函数内部,valgrind报告内存泄漏

我是C的新手,我正在做玩具程序来学习它.以下代码编译,输出正确,但Valgrind报告内存泄漏:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "graph.h"

void add_vertex(vertex *v_p, char *name) {
    if(strlen(name) == 0) { 
        printf("error");
    }
    v_p->name = (char *)malloc(strlen(name) + 1);
    if(v_p->name == NULL) {
        printf("error");
    }
    strcpy(v_p->name, name);
    v_p->cluster = -1;
    v_p->deleted = 0;
    printf("added vertex.\n");
}

void free_vertex(vertex *ver) {
    if(ver->name) {free(ver->name);printf("free'd name\n");}
    free(ver);

}

int main() {
    int Nu = 0;
    vertex *arr = (vertex *)malloc(2 * sizeof(vertex));
    vertex *_temp;
    int i =0;
    add_vertex(arr, "Hello");
    add_vertex(arr+1, "World");
    _temp = (vertex *)realloc(arr, …
Run Code Online (Sandbox Code Playgroud)

c malloc valgrind memory-leaks

1
推荐指数
1
解决办法
4011
查看次数

标签 统计

c ×1

c# ×1

c++ ×1

malloc ×1

memory-leaks ×1

pipe ×1

valgrind ×1