I’m trying to use CoCreateGuid(GUID* guid) to create a guid for objects in my application. I am getting a few errors trying to use this function.
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
Here is the code I am using, not much to it at the moment.
#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
}
It says to use a GUID pointer for the argument but I keep getting these errors.
Help is much appreciated!
A using directive (
using namespace System;) in one of your headers (probablyAutomationCPP.h) is causing the problem.You’re indirectly including
servprov.h, which has a definition for::IServiceProvider, and you’ve got the using directive which is bringingSystem::IServiceProviderinto the global scope. This causes ambiguity for any use ofIServiceProviderthat isn’t fully qualified.Get rid of the using directive, and instead use using declarations only for the symbols in namespace
Systemthat you actually need.