Alternative to __uuidof in C
Asked Answered
V

3

16

I'm working with a C project that's using DirectX and I've run into a problem. Certain DX calls require a IID object, typically generated with __uuidof. One thing this is required for is creating a RenderTargetView. The DirectX samples/tutorials do this:

ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );

When I try to call __uuidof in my C code, I get an compiler error: Error 19 error C4233: nonstandard extension used : '__uuidof' keyword only supported in C++, not C. DirectX has a C interface, so I imagine there must be a way to do this, but I have no idea what it would be. Anyone know?

Vigilantism answered 15/1, 2012 at 9:40 Comment(1)
C programmers typically just define the UUID as a constant somewhere in their source file.Transcaucasia
A
16

__uuidof is only available in C++, as error described. I think you already have definitions of the GUIDs of the interfaces for C available in DX header files.

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/1306b57f-4b75-4f0c-b4f3-9bcc1e3a0dd6

From d3d11.h:

EXTERN_C const IID IID_ID3D11Texture2D;

Use this instead of __uuidof(ID3D11Texture2D).

Assistance answered 15/1, 2012 at 9:46 Comment(2)
Yep, that did it. The only other change I had to make was to link with dxguid.lib. Thanks.Vigilantism
Upvoted, it might be nice to add you'll also need to add the adress-of operator & if you are really using C. ID3D10Texture2D* pBackBuffer; swapchain->lpVtbl->GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, &pBackBuffer);Cattail
O
2

you have to find the uuid or "guid" of the class. it should be in some header in the directx sdk (older) or in the Platform SDK (on Windows Vista and Windows 7) - depends on what you are using.

Oakum answered 15/1, 2012 at 10:0 Comment(0)
R
0

Generally the UIID of a class is defined in a C interface header file as the class name prepended by by the prefix "IID_" (see the accepted answer). When creating plain C projects if you want keep using the C++ form you can create a simple macro:

#ifndef __cplusplus
#define __uuidof(iid) IID_##iid
#endif

This will work if for the class IID exists a definition in the standard form IID_<classname>.

Rangy answered 25/11, 2023 at 11:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.