C++;Windows RPC如何定义MIDL可以传输以null结尾的字符数组 P>我的项目是用C++ Windows RPC从客户端到服务器上传图像(512×512)。我以前不使用WIN RPC,所以我尝试了一些示例,包括向服务器发送基本的“Hello world”消息,但最大的问题是该函数无法发送未签名的字符*包含“\0”。我的意思是字符数组中有很多'\0'字符,它们无法发送到服务器

C++;Windows RPC如何定义MIDL可以传输以null结尾的字符数组 P>我的项目是用C++ Windows RPC从客户端到服务器上传图像(512×512)。我以前不使用WIN RPC,所以我尝试了一些示例,包括向服务器发送基本的“Hello world”消息,但最大的问题是该函数无法发送未签名的字符*包含“\0”。我的意思是字符数组中有很多'\0'字符,它们无法发送到服务器,c++,windows,opencv,rpc,C++,Windows,Opencv,Rpc,我想这是因为我定义了错误的MIDL函数 我试过: void Output( [in, out, size_is(1048576), string] unsigned char* szString); 另一个 无效输出1( [in,length_为(1048576)]无符号字符[]) 但两者都不起作用 我使用opencv3.2将图像读取到Mat结构,它可以获取Mat数据并使用memcpy复制Mat.data,然后在本地客户端创建一个新图像。但当我将Mat.data发送到服务器时,Mat.d

我想这是因为我定义了错误的MIDL函数

  • 我试过:

    void Output(
    [in, out, size_is(1048576), string] unsigned char* szString);
    
  • 另一个

    无效输出1( [in,length_为(1048576)]无符号字符[])

但两者都不起作用

我使用opencv3.2将图像读取到Mat结构,它可以获取Mat数据并使用memcpy复制Mat.data,然后在本地客户端创建一个新图像。但当我将Mat.data发送到服务器时,Mat.data中的第一个字符是“\0”。无法将所有Mat.data发送到服务器

My Client core code(It has include all require header) is

    Mat I = imread("U:\\normal.jpg", IMREAD_ANYDEPTH);
if (I.empty())
{
    std::cout << "!!! Failed imread(): image not found" << std::endl;
    // don't let the execution continue, else imshow() will crash.
}
if (!I.data) {
    std::cout << "can't open or find image" << std::endl;
    //return -1;
}
I.convertTo(I, CV_32F);

I = (I.reshape(0, 1)); // to make it continuous

char tr[512*512*4];
memcpy_s(tr, 512 * 512 * 4, I.data, 512*512 * 4);
//snprintf(tr, 512*512*4,"%s", I.data);

Mat out = Mat(512,512, CV_32F, &tr[0]);
namedWindow("Display window", CV_WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", out);
waitKey(5000);
我的客户机核心代码(它有include all require头)是
Mat I=imread(“U:\\normal.jpg”,imread\U ANYDEPTH);
if(I.empty())
{

std::您是否应该小心这样的大分配。您可能希望使用
new
来获得更大的字符缓冲区。@tadman嗨,谢谢!我尝试为字符提供更大的缓冲区,但仍然无法将它们发送到服务器。我还尝试了更小的128*128图标,但当字符为“\0”时,它将停止在那里。。听起来像您有几个问题,其中之一是数据被解释为以空分隔的C样式字符串。
RpcTryExcept
{
    std::clog << "Calling Open" << std::endl;
    output((unsigned char* )tr); // process the function, send data to server
    //output1((unsigned char* )tr);
}