错误3699,为对象创建GUID

Che*_*aoh 3 c++ c++-cli visual-c++

我正在尝试使用CoCreateGuid(GUID*guid)为我的应用程序中的对象创建一个guid.尝试使用此功能时出现一些错误.

error C3699: '*' : cannot use this indirection on type 'IServiceProvider' in servprov.h
error C2872: 'IServiceProvider' : ambiguous symbol in servprov.h
error C2371: 'IServiceProvider' : redefinition; different basic types in servprov.h
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码,目前并不多.

#include "Stdafx.h"
#include "AutomationCPP.h"
#include <Rpc.h>
#include <Guiddef.h>

using namespace System;

void AutomationCPP::CustomAutomationCPP::Instantiate()
{
    long result;
    unsigned char *guidstr;
    HRESULT hr;
    GUID *UIAguid;

    CoCreateGuid(UIAguid);  //errors here
}
Run Code Online (Sandbox Code Playgroud)

它说要为参数使用GUID指针,但我不断收到这些错误.非常感谢帮助!

ild*_*arn 11

using namespace System;你的一个标题(可能AutomationCPP.h)中的using指令()导致问题.

您是间接包含的servprov.h,它有一个定义::IServiceProvider,并且您已经获得了System::IServiceProvider进入全局范围的using指令.这导致IServiceProvider不完全合格的任何使用的模糊性.

摆脱using指令,而只是使用声明,仅用于System实际需要的命名空间中的符号.