且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我需要一些这方面的帮助:

更新时间:2023-11-20 12:48:52

You are correct: if you run a command prompt as admin, all apps you open from it also automatically have admin rights and privileges.

(But you can use runas to \"promote\" an app from the command line: how to run a program as adminitrator via the command line[^])



Your problem is probably not admin: as pwasser says, \"error code 87\" is INVALID PARAMETER, not an access violation.

So run VS as admin, then run your code in the debugger and try to find exactly where the problem originates. At the moment, it could be almost anywhere!
You are correct: if you run a command prompt as admin, all apps you open from it also automatically have admin rights and privileges.
(But you can use runas to "promote" an app from the command line: how to run a program as adminitrator via the command line[^])

Your problem is probably not admin: as pwasser says, "error code 87" is INVALID PARAMETER, not an access violation.
So run VS as admin, then run your code in the debugger and try to find exactly where the problem originates. At the moment, it could be almost anywhere!


This may already solved. But I will try to explain how to handle this kind of errors.



As alread mentioned error code 87 is ERROR_INVALID_PARAMETER. So debugging won’t help much besides the ability to check the contents of the variables passed to the API function that fails with this error code.



Instead check the documentation for the API function and if your parameters met the requirements. HttpAddUrl function (Windows)[^] has only three parameters:



ReqQueueHandle is probably valid because you included an error check when calling the function that returns the handle. When passing invalid handles to functions most will also fail with ERROR_INVALID_HANDLE instead of the general error code 87.



The pReserved parameter must be NULL which it is.



So the only remaining parameter is pFullyQualifiedUrl:

This may already solved. But I will try to explain how to handle this kind of errors.

As alread mentioned error code 87 is ERROR_INVALID_PARAMETER. So debugging won't help much besides the ability to check the contents of the variables passed to the API function that fails with this error code.

Instead check the documentation for the API function and if your parameters met the requirements. HttpAddUrl function (Windows)[^] has only three parameters:

ReqQueueHandle is probably valid because you included an error check when calling the function that returns the handle. When passing invalid handles to functions most will also fail with ERROR_INVALID_HANDLE instead of the general error code 87.

The pReserved parameter must be NULL which it is.

So the only remaining parameter is pFullyQualifiedUrl:
Quote:

A pointer to a Unicode string that contains a properly formed UrlPrefix string[^] that identifies the URL to be registered.

A pointer to a Unicode string that contains a properly formed UrlPrefix string[^] that identifies the URL to be registered.



It must be a Unicode string. This is met by using wide chars. So the error must be sourced by the string itself. There is a link that describes the string format. Check if your string is a valid UrlPrefix. It should be still visible in the command window making it easy to check it without using the debugger.





It is always a good idea to read the complete API function documentation because it may contain important information. This includes the Remarks section which might include information about additional failure scenarios:


It must be a Unicode string. This is met by using wide chars. So the error must be sourced by the string itself. There is a link that describes the string format. Check if your string is a valid UrlPrefix. It should be still visible in the command window making it easy to check it without using the debugger.


It is always a good idea to read the complete API function documentation because it may contain important information. This includes the Remarks section which might include information about additional failure scenarios:

Quote:

It is not possible to register URLs having different schemes on the same port. That is, \"http\" and \"https\" schemes cannot coexist on a port.

It is not possible to register URLs having different schemes on the same port. That is, "http" and "https" schemes cannot coexist on a port.

SO the function will fail when called again with a different scheme.



In this case there is also another important note:

SO the function will fail when called again with a different scheme.

In this case there is also another important note:

Quote:

Starting with HTTP Server API Version 2.0, applications should call HttpAddUrlToUrlGroup to register a URL; HttpAddUrl should not be used.

Starting with HTTP Server API Version 2.0, applications should call HttpAddUrlToUrlGroup to register a URL; HttpAddUrl should not be used.

It seems that you are using outdated code.

[/EDIT]

It seems that you are using outdated code.
[/EDIT]