只是一个补充,如果有人不能运行 difxapi 函数,你需要通过某种方式将你的项目链接到difxapi.h
WDKdifxapi.lib
附带的。
快速的方法,只需复制difxapi.h
并difxapi.lib
添加到您的文件夹项目并添加到您的项目中。请注意在 wdk 文件夹中选择与 x86 兼容的文件。
一个简单的代码示例,仅用于测试,使用在 win 7 32bit 上运行的 C:
#include <windows.h>
#include <stdio.h>
#include "difxapi.h"
int main(void)
{
DWORD dwRet = 0;
PCTSTR DriverPackageInfPath = TEXT("D:\\MYDRIVER.INF");
DWORD Flags = 0;
INSTALLERINFO InstallerInfo;
BOOL bNeedReboot;
char chName[] = "Thing Name";
char chGUID[] = "{4D36E979-E325-11CE-BFC1-08002BE10318}"; //printer GUID
InstallerInfo.pDisplayName = &chName;
InstallerInfo.pProductName = &chName;
InstallerInfo.pMfgName = &chName;
InstallerInfo.pApplicationId = &chGUID;
dwRet = DriverPackageInstall( DriverPackageInfPath, Flags, &InstallerInfo , &bNeedReboot );
switch(dwRet)
{
case ERROR_SUCCESS:
printf("\n\n ERROR_SUCCESS - Ret: %d, %xh", dwRet, dwRet);
break;
case CERT_E_EXPIRED:
printf("\n\n CERT_E_EXPIRED - Ret: %d, %xh", dwRet, dwRet);
break;
case CERT_E_UNTRUSTEDROOT:
printf("\n\n CERT_E_UNTRUSTEDROOT - Ret: %d, %xh", dwRet, dwRet);
break;
case CERT_E_WRONG_USAGE:
printf("\n\n CERT_E_WRONG_USAGE - Ret: %d, %xh", dwRet, dwRet);
break;
case CRYPT_E_FILE_ERROR:
printf("\n\n CRYPT_E_FILE_ERROR - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_ACCESS_DENIED:
printf("\n\n ERROR_ACCESS_DENIED - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_BAD_ENVIRONMENT:
printf("\n\n ERROR_BAD_ENVIRONMENT - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_CANT_ACCESS_FILE:
printf("\n\n ERROR_CANT_ACCESS_FILE - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_FILE_NOT_FOUND:
printf("\n\n ERROR_FILE_NOT_FOUND - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_FILENAME_EXCED_RANGE:
printf("\n\n ERROR_FILENAME_EXCED_RANGE - Ret: %d, %xh", dwRet, dwRet);
break;
/*case ERROR_IN_WOW64:
printf("\n\n ERROR_IN_WOW64 - Ret: %d, %xh", dwRet, dwRet);
break;*/
case ERROR_INSTALL_FAILURE:
printf("\n\n ERROR_INSTALL_FAILURE - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_INVALID_CATALOG_DATA:
printf("\n\n ERROR_INVALID_CATALOG_DATA - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_INVALID_NAME:
printf("\n\n ERROR_INVALID_NAME - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_INVALID_PARAMETER:
printf("\n\n ERROR_INVALID_PARAMETER - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_NO_DEVICE_ID:
printf("\n\n ERROR_NO_DEVICE_ID - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_NO_MORE_ITEMS:
printf("\n\n ERROR_NO_MORE_ITEMS - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_NO_SUCH_DEVINST:
printf("\n\n ERROR_NO_SUCH_DEVINST - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_OUTOFMEMORY:
printf("\n\n ERROR_OUTOFMEMORY - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_SHARING_VIOLATION:
printf("\n\n ERROR_SHARING_VIOLATION - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_SIGNATURE_OSATTRIBUTE_MISMATCH:
printf("\n\n ERROR_SIGNATURE_OSATTRIBUTE_MISMATCH - Ret: %d, %xh", dwRet, dwRet);
break;
case ERROR_UNSUPPORTED_TYPE:
printf("\n\n ERROR_UNSUPPORTED_TYPE - Ret: %d, %xh", dwRet, dwRet);
break;
case TRUST_E_NOSIGNATURE:
printf("\n\n TRUST_E_NOSIGNATURE - Ret: %d, %xh", dwRet, dwRet);
break;
default:
printf("\n\n default - Ret: %d, %xh", dwRet, dwRet);
break;
}
printf("\n\n");
system("pause");
return 1;
}