gpt4 book ai didi

c++ - HttpQueryServiceConfiguration 总是返回 ERROR_INSUFFICIENT_BUFFER

转载 作者:行者123 更新时间:2023-11-28 05:52:01 25 4
gpt4 key购买 nike

#include "stdafx.h"
#include "Http.h"
#pragma comment (lib,"Httpapi.lib")

int _tmain(int argc, _TCHAR* argv[])
{
HTTPAPI_VERSION HttpApiVersion = HTTPAPI_VERSION_1;
ULONG ret = NO_ERROR;
HRESULT hr = S_OK;
HTTPAPI_VERSION ver = HTTPAPI_VERSION_1;
ret = HttpInitialize(ver,HTTP_INITIALIZE_SERVER|HTTP_INITIALIZE_CONFIG,NULL);
if(ret!=NO_ERROR)
{
return 0;
}

HTTP_SERVICE_CONFIG_ID configId = HttpServiceConfigIPListenList;
HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY* query=NULL;
ULONG size=1000;
ULONG re = HttpQueryServiceConfiguration(NULL,configId,NULL,NULL,query,NULL,&size,NULL);
printf("re = %d",re);
getchar();
return 0;
}

这个重新结果总是 122 (ERROR_INSUFFICIENT_BUFFER) 。我不知道原因。这是 HttpQueryServiceConfiguration 函数的链接: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364491

最佳答案

根据您链接到的引用,您作为函数指针传递的 sizepReturnLength,它是一个输出 参数,并且是

A pointer to a variable that receives the number of bytes to be written in the output buffer.

[强调我的]

您提供的缓冲区大小在之前的参数中,即 OutputConfigInfoLength 参数中。当然,如果你想写入一些数据,你需要实际提供一个缓冲区来存储它,你传递 NULL 作为参数(query 被初始化为 NULL).

另请注意,如果函数因 ERROR_INSUFFICIENT_BUFFER 而失败,作为 pReturnLength 传递的变量将包含函数成功所需的实际 长度。因此,您应该做的是首先使用零缓冲区大小调用它,以获得所需的大小,然后再次调用它以实际获取信息。

有点像

HTTP_SERVICE_CONFIG_ID configId = HttpServiceConfigIPListenList;
ULONG size;
ULONG re = HttpQueryServiceConfiguration(NULL,configId,NULL,0,NULL,0,&size,NULL);

if (re != ERROR_INSUFFICIENT_BUFFER)
{
// We got an unknown error, handle it
}
else
{
// Allocate a buffer big enough for the data
HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY* query =
reinterpret_cast<HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY*>(new char[size]);

// Call the function again
re = HttpQueryServiceConfiguration(NULL,configId,NULL,0,query,size,&size,NULL);

// Here you should have the information you want in `query`
// Use the data

// Free the memory
delete[] query;
}

关于c++ - HttpQueryServiceConfiguration 总是返回 ERROR_INSUFFICIENT_BUFFER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35032303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com