c++ - HttpQueryServiceConfiguration always return me ERROR_INSUFFICIENT_BUFFER -


#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; } 

this re result 122 (error_insufficient_buffer) . don't know reson. link of httpqueryserviceconfiguration function: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364491

according reference link to, size pass pointer function preturnlength output argument , is

a pointer variable receives number of bytes written in output buffer.

[emphasis mine]

the size of buffer provide in argument before, outputconfiginfolength argument. of course, if want data written need provide buffer store it, , pass null argument (query initialized null).

also note if function fails error_insufficient_buffer variable passed preturnlength contain actual length needed function succeed. should first call 0 buffer size, size needed, , call again information.

something like

http_service_config_id configid = httpserviceconfigiplistenlist; ulong size; ulong re = httpqueryserviceconfiguration(null,configid,null,0,null,0,&size,null);  if (re != error_insufficient_buffer) {     // got unknown error, handle } else {     // allocate buffer big enough data     http_service_config_ip_listen_query* query =         reinterpret_cast<http_service_config_ip_listen_query*>(new char[size]);      // call function again     re = httpqueryserviceconfiguration(null,configid,null,0,query,size,&size,null);      // here should have information want in `query`     // use data      // free memory     delete[] query; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -