Answered by:
WinRT WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) symbols creating problems in using #import code

Question
-
I am not able to use a COM dll which i #import-ed because it doesn't compile. For some reason, part of the stuff in the tlh file resulting from the import uses stuff under WINAPI_PARTITION_DESKTOP, which prevents it from compiling. For example, _com_error uses IErrorInfo below, which is deffed out.
#ifndef __IErrorInfo_INTERFACE_DEFINED__
#define __IErrorInfo_INTERFACE_DEFINED__/* interface IErrorInfo */
/* [unique][uuid][object] */typedef /* [unique] */ __RPC_unique_pointer IErrorInfo *LPERRORINFO;
EXTERN_C const IID IID_IErrorInfo;#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1CF2B120-547D-101B-8E65-08002B2BD119")
IErrorInfo : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetGUID(
/* [out] */ __RPC__out GUID *pGUID) = 0;
virtual HRESULT STDMETHODCALLTYPE GetSource(
/* [out] */ __RPC__deref_out_opt BSTR *pBstrSource) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDescription(
/* [out] */ __RPC__deref_out_opt BSTR *pBstrDescription) = 0;
virtual HRESULT STDMETHODCALLTYPE GetHelpFile(
/* [out] */ __RPC__deref_out_opt BSTR *pBstrHelpFile) = 0;
virtual HRESULT STDMETHODCALLTYPE GetHelpContext(
/* [out] */ __RPC__out DWORD *pdwHelpContext) = 0;
};
#else /* C style interface */typedef struct IErrorInfoVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IErrorInfo * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
__RPC__deref_out _Result_nullonfailure_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IErrorInfo * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IErrorInfo * This);
HRESULT ( STDMETHODCALLTYPE *GetGUID )(
__RPC__in IErrorInfo * This,
/* [out] */ __RPC__out GUID *pGUID);
HRESULT ( STDMETHODCALLTYPE *GetSource )(
__RPC__in IErrorInfo * This,
/* [out] */ __RPC__deref_out_opt BSTR *pBstrSource);
HRESULT ( STDMETHODCALLTYPE *GetDescription )(
__RPC__in IErrorInfo * This,
/* [out] */ __RPC__deref_out_opt BSTR *pBstrDescription);
HRESULT ( STDMETHODCALLTYPE *GetHelpFile )(
__RPC__in IErrorInfo * This,
/* [out] */ __RPC__deref_out_opt BSTR *pBstrHelpFile);
HRESULT ( STDMETHODCALLTYPE *GetHelpContext )(
__RPC__in IErrorInfo * This,
/* [out] */ __RPC__out DWORD *pdwHelpContext);
END_INTERFACE
} IErrorInfoVtbl;interface IErrorInfo
{
CONST_VTBL struct IErrorInfoVtbl *lpVtbl;
};#ifdef COBJMACROS
#define IErrorInfo_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )#define IErrorInfo_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )#define IErrorInfo_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IErrorInfo_GetGUID(This,pGUID) \
( (This)->lpVtbl -> GetGUID(This,pGUID) )#define IErrorInfo_GetSource(This,pBstrSource) \
( (This)->lpVtbl -> GetSource(This,pBstrSource) )#define IErrorInfo_GetDescription(This,pBstrDescription) \
( (This)->lpVtbl -> GetDescription(This,pBstrDescription) )#define IErrorInfo_GetHelpFile(This,pBstrHelpFile) \
( (This)->lpVtbl -> GetHelpFile(This,pBstrHelpFile) )#define IErrorInfo_GetHelpContext(This,pdwHelpContext) \
( (This)->lpVtbl -> GetHelpContext(This,pdwHelpContext) )#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IErrorInfo_INTERFACE_DEFINED__ */Saturday, January 14, 2012 4:32 AM
Answers
-
The incompatibliity between comdef.h and building with /ZW (C++/CX) is a known bug. It should be fixed in the future. Right now, you're not going to be able to use #import in C++/CX.
- Marked as answer by Steve HorneMicrosoft employee, Moderator Tuesday, February 14, 2012 10:16 PM
Thursday, February 9, 2012 9:43 PMModerator
All replies
-
Just to clarify, the error/grayed out sections occur in #include <comdef.h> which needs to be included before the #import "foo.dll" so that the interfaces used/spat out as implemented by the import can see it.Saturday, January 14, 2012 4:37 AM
-
It gets worse. After i hacked it to redefine this IErrorInfo section elsewhere, i run into a fresh set of common defines which are defined in windows.h/winbase.h under "WINAPI_PARTITION_DESKTOP" while the metro app uses WINAPI_PARTITION_APP.
Error 1 error C3861: 'LocalFree': identifier not found c:\program files (x86)\microsoft visual studio 11.0\vc\include\comdef.h 154 1 qbsdkWinRTComponent
Error 2 error C3861: 'lstrlen': identifier not found c:\program files (x86)\microsoft visual studio 11.0\vc\include\comdef.h 244 1 qbsdkWinRTComponent
Error 3 error C3861: 'LocalAlloc': identifier not found c:\program files (x86)\microsoft visual studio 11.0\vc\include\comdef.h 253 1 qbsdkWinRTComponent
4 IntelliSense: identifier "LocalFree" is undefined c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\comdef.h 154 9 qbsdkWinRTComponent
5 IntelliSense: identifier "lstrlen" is undefined c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\comdef.h 244 24 qbsdkWinRTComponent
6 IntelliSense: identifier "LocalAlloc" is undefined c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\comdef.h 253 32 qbsdkWinRTComponentSaturday, January 14, 2012 4:54 AM -
The incompatibliity between comdef.h and building with /ZW (C++/CX) is a known bug. It should be fixed in the future. Right now, you're not going to be able to use #import in C++/CX.
- Marked as answer by Steve HorneMicrosoft employee, Moderator Tuesday, February 14, 2012 10:16 PM
Thursday, February 9, 2012 9:43 PMModerator -
I have the same problem : is it fixed in VS2015, and if not, is make use of #import in C++/CX planned ?
thanks in advance
Wednesday, June 3, 2015 9:12 AM