Cannot open include file : 'strsafe.h': No such file or directory

shifters 2010-03-29 09:37:01
编译的时候出现错误,怎么解决? 哪位大虾指教一下:
----------Configuration: iseldr - Win32 Debug----------
Compiling...
iseldr.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\iseldr.cpp(15) : fatal error C1083: Cannot open include file : 'strsafe.h': No such file or directory
执行 cl.exe 时出错.

iseldr.obj - 1 error(s), 0 warning(s)

源代码是从微软网站上找的,不知道为何编译出错。。。郁闷ing....

/* You can build the following code sample by using the following command-line arguments after you select the correct build environment, such as XP Checked:

cl -nologo -DUNICODE <SourceFile.cpp> -link setupapi.lib

NOTE: <SourceFile.cpp> represents the name of the source file.
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <objbase.h>
#include <tchar.h>
#include <setupapi.h>
#include <strsafe.h>

#define SIZECHARS(x) (sizeof((x))/sizeof(TCHAR))
//
// The following is the prototype for the newdev!InstallSelectedDriver API.
//
typedef
BOOL
(*PINSTALLSELECTEDDRIVER)(
HWND hwndParent,
HDEVINFO DeviceInfoSet,
LPCWSTR Reserved,
BOOL Backup,
PDWORD pReboot
);


int
__cdecl
wmain(
IN int argc,
IN WCHAR *argv[]
)
{
DWORD Err = NO_ERROR;
HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA DeviceInfoData;
SP_DRVINFO_DATA DriverInfoData;
SP_DEVINSTALL_PARAMS DeviceInstallParams;
TCHAR NewDevPath[MAX_PATH];
HMODULE hNewDev = NULL;
PINSTALLSELECTEDDRIVER pInstallSelectedDriver = NULL;
DWORD Reboot;

//
// The command line will contain a device instance Id and a full
// path of an INF.
//
if (argc < 3) {
printf("Usage: iseldr \"device instance id\" \"full path to the INF file\"\n");
return ERROR_INVALID_PARAMETER;
}

printf("%ws\n", argv[1]);
printf("%ws\n", argv[2]);

//
// Create an empty device information list.
//
DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
goto clean0;
}

//
// Add the device that is referenced by the device instance id parameter
// to the device information list.
//
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiOpenDeviceInfo(DeviceInfoSet,
(PCWSTR)argv[1],
NULL,
0,
&DeviceInfoData)) {
Err = GetLastError();
goto clean0;
}

//
// InstallSelectedDriver works on the selected device and on the
// selected driver on that device. Therefore, set this device as the
// selected one in the device information list.
//
if (!SetupDiSetSelectedDevice(DeviceInfoSet,
&DeviceInfoData)) {
Err = GetLastError();
goto clean0;
}

//
// You now have a SP_DEVINFO_DATA structure
// representing your device. Next, get a SP_DRVINFO_DATA
// structure to install on that device.
//
DeviceInstallParams.cbSize = sizeof(DeviceInstallParams);
if (!SetupDiGetDeviceInstallParams(DeviceInfoSet,
&DeviceInfoData,
&DeviceInstallParams)) {
Err = GetLastError();
goto clean0;
}

//
// Only build the driver list out of the passed-in INF.
// To do this, set the DI_ENUMSINGLEINF flag, and copy the
// full path of the INF into the DriverPath field of the
// DeviceInstallParams structure.
//
DeviceInstallParams.Flags |= DI_ENUMSINGLEINF;
if (FAILED(StringCchCopy(DeviceInstallParams.DriverPath,
SIZECHARS(DeviceInstallParams.DriverPath),
argv[2]))) {
//
// The file path that was passed in was too big.
//
Err = ERROR_INVALID_PARAMETER;
goto clean0;
}

//
// Set the DI_FLAGSEX_ALLOWEXCLUDEDDRVS flag so that you can use
// this INF even if it is marked as ExcludeFromSelect.
// ExcludeFromSelect means do not show the INF in the legacy Add
// Hardware Wizard.
//
DeviceInstallParams.FlagsEx |= DI_FLAGSEX_ALLOWEXCLUDEDDRVS;

if (!SetupDiSetDeviceInstallParams(DeviceInfoSet,
&DeviceInfoData,
&DeviceInstallParams)) {
Err = GetLastError();
goto clean0;
}

//
// Build up a Driver Information List from the specified INF.
// Build a compatible driver list, meaning only include the
// driver nodes that match one of the hardware or compatible Ids of
// the device.
//
if (!SetupDiBuildDriverInfoList(DeviceInfoSet,
&DeviceInfoData,
SPDIT_COMPATDRIVER)) {
Err = GetLastError();
goto clean0;
}

//
// Pick the best driver in the list of drivers that was built.
//
if (!SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV,
DeviceInfoSet,
&DeviceInfoData)) {
Err = GetLastError();
goto clean0;
}

//
// Get the selected driver node.
// Note: If this list does not contain any drivers, this call
// will fail with ERROR_NO_DRIVER_SELECTED.
//
DriverInfoData.cbSize = sizeof(DriverInfoData);
if (!SetupDiGetSelectedDriver(DeviceInfoSet,
&DeviceInfoData,
&DriverInfoData)) {
Err = GetLastError();
goto clean0;
}

//
// At this point, you have a valid SP_DEVINFO_DATA structure and a
// valid SP_DRVINFO_DATA structure.
// Load newdev.dll, GetProcAddress(InstallSelectedDriver), and call
// that API.
//
// To be more secure, make sure to load the newdev.dll file from the
// system 32 directory.
//
if (GetSystemDirectory(NewDevPath, SIZECHARS(NewDevPath)) == 0) {
Err = GetLastError();
goto clean0;
}

if (FAILED(StringCchCat(NewDevPath, SIZECHARS(NewDevPath), TEXT("\\NEWDEV.DLL")))) {
Err = ERROR_INSUFFICIENT_BUFFER;
goto clean0;
}

hNewDev = LoadLibrary(NewDevPath);
if (!hNewDev) {
Err = GetLastError();
goto clean0;
}

pInstallSelectedDriver = (PINSTALLSELECTEDDRIVER)GetProcAddress(hNewDev, "InstallSelectedDriver");
if (!pInstallSelectedDriver) {
Err = GetLastError();
goto clean0;
}

//
// Call pInstallSelectedDriver to install the selected driver on
// the selected device.
//
pInstallSelectedDriver(NULL,
DeviceInfoSet,
NULL,
TRUE,
&Reboot);

if (Reboot & (DI_NEEDREBOOT | DI_NEEDRESTART)) {
//
// A reboot is required.
//
}

clean0:
if (hNewDev) {
FreeLibrary(hNewDev);
hNewDev = NULL;
}

if (DeviceInfoSet != INVALID_HANDLE_VALUE) {
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
DeviceInfoSet = INVALID_HANDLE_VALUE;
}

printf("iseldrv returned 0x%X\n", Err);
return Err;
}
...全文
2591 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ff471199 2011-02-16
  • 打赏
  • 举报
回复
装plaformSDK,将SDK的include设置添加到工程的include文件列表下
ltq6521606 2010-08-25
  • 打赏
  • 举报
回复
我也出现这问题了
原来没有问题的代码不知为何
我修复漏洞就出毛病了
是不是更新漏洞出的错啊?

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧