2

アプリのフォルダーを作成して、/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();
        }
        ....
    };
}

gamepad.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
{
    ....
}

configure.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");
    }
}
4

2 に答える 2

4

IServerProvider確かにあいまいです。servprov.h Windows SDK ヘッダー ファイルの COM インターフェイス タイプと、System 名前空間の .NET インターフェイス タイプの両方として存在します。

問題を再現する最も簡単な方法は、using namespaceディレクティブを間違った場所に置くことです。

  #include "stdafx.h"
  using namespace System;
  #include <ShlObj.h>

バム、18エラー。正しく注文すれば問題ありません:

  #include "stdafx.h"
  #include <ShlObj.h>
  using namespace System;

ディレクティブを使用している人には注意してください。あいまいさを作り出すのが得意です。

于 2015-01-12T01:08:24.037 に答える