I am calling SetupCopyOEMInf to copy a .inf file for a device driver (the MSFT docs say: 'SetupAPI continues to be used for installing device drivers').

The call is returning false, so I am then calling GetLastError as the docs say (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM). The value returned here is E000024B or 3758096971 in decimal. However, when I call FormatMessage as prescribed with the return value from GetLastError, lpBuffer is NULL.

Also trying to figure out why SetupCopyOEMInf would be failing (it seems to work on some .inf files but not others). This is Windows 8.1

Puzzling...Any ideas out there?

Thanks!

Code:

BOOL result = SetupCopyOEMInf(_T("C:\\Users\\edward\\Desktop\\_Test\\cncport.inf"), NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL);

//result is FALSE

LPVOID lpBuffer;
DWORD dw = GetLastError();

DWORD dwMsg = FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER |
    FORMAT_MESSAGE_FROM_SYSTEM |
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    dw,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    (LPTSTR)&lpBuffer,
    2048, NULL);
有帮助吗?

解决方案

FORMAT_MESSAGE_FROM_SYSTEM does not support all error codes. The one you found is ERROR_FILE_HASH_NOT_IN_CATALOG which is not covered by FORMAT_MESSAGE_FROM_SYSTEM. The setupapi.h errors do not appear to have any predefined text for them in a system message resource. You will have to write the error strings yourself.

其他提示

Even though this post was created a while ago, you actually can get the text by using the HRESULT_FROM_SETUPAPI macro (as posted by Microsoft here http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011%28v=vs.85%29.aspx). This will map the error code returned to one that can be used in the FormatMessage function.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top