我正在尝试为我的应用程序创建一个文件夹,/AppData/local
以便可以在其中保存一些 ini 文件,我尝试使用以下方法获取目标路径:
#include <ShlObj.h>
if (SHGetKnownFolderPath (FOLDERID_LocalAppData, 0, NULL, &tempPath) == S_OK)
{
....
}
它不起作用并给我这些错误:
Error 1 error C2872: 'IServiceProvider' : ambiguous symbol c:\program files\windows kits\8.0\include\um\ocidl.h 6482 1 Project2
Error 2 error C2872: 'IServiceProvider' : ambiguous symbol C:\Program Files\Windows Kits\8.0\Include\um\shobjidl.h 9181 1 Project2
我尝试在项目设置中添加#pragma comment (lib, "Shell32.lib")
和链接Shell32.lib
,但没有任何改变。
当我删除时错误消失,#include <ShlObj.h>
但SHGetKnownFolderPath
函数变得未定义。我怎样才能解决这个问题?
注意:我在 Windows 7 上
编辑:我的项目头文件是:
MyForm.h
#pragma once
#define CRTDBG_MAP_ALLOC
#include "gamepad.h"
#include "configure.h"
#include <stdlib.h>
#include <crtdbg.h>
#include <Dbt.h>
namespace Project2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Diagnostics;
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
this->gamepad = gcnew Gamepad();
this->SETTINGS = gcnew Settings();
}
....
};
}
游戏手柄.h
#pragma once
#include <Windows.h>
#include <WinUser.h>
#include <tchar.h>
#define _USE_MATH_DEFINES
#include <math.h>
extern "C"
{
#include <hidsdi.h>
}
#include "InputHandler.h"
#include "keycodes.h"
using namespace System;
public ref class Gamepad
{
....
}
配置.h
#pragma once
#include "keycodes.h"
#include <Windows.h>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <msclr\marshal.h>
using namespace System;
using namespace System::Diagnostics;
using namespace System::IO;
using namespace msclr::interop;
public ref class Settings
{
public:
Settings(void)
{
PWSTR tempPath;
if (SUCCEEDED (SHGetKnownFolderPath (FOLDERID_LocalAppData, 0, NULL, &tempPath)))
Debug::WriteLine (gcnew String (tempPath));
else Debug::WriteLine ("Failed");
}
}