Use of GUID constants

KlausO via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 9 10:35:31 PST 2016


Dear list,

I use DMD 2.070.0 I try to access COM Interfaces via the declarations in 
core.sys.windows.*
I have some problems and maybe someone could give me a usage hint.
Have a look at the following (relatively meaningless) sample program 
which demonstrates the problem.

IMHO the problem is that GUID constants are declared as enums in the
winapi bindings (see src\druntime\import\core\sys\windows\uuid.d).
Within the dclient.d sample which comes with dmd they are explicitely
defined as GUIDs:

GUID IID_IHello  = { 0x00421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] };

So maybe they should be declared as "extern GUID ..." because they also 
seem to be defined in windows\lib\uuid.lib which comes with DMD.
What do you think ?

Thanks

-- KlausO


Sample program:


import std.stdio;
import std.utf;
import core.stdc.stdlib;

import core.sys.windows.windows;
import core.sys.windows.com;
import core.sys.windows.objidl;

bool CreateCompoundDoc(const wstring filename)
{
	IStorage storage;

	HRESULT hr = StgCreateDocfile( toUTF16z(filename),
								   STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT | 
STGM_CREATE,
								   0,
								  &storage);

	if (S_OK == hr)
	{
		IUnknown pUnk;

		//
		// Does not compile:
		//
		//  Error: function 
core.sys.windows.unknwn.IUnknown.QueryInterface(const(GUID)* riid, 
void** pvObject) is not callable using argument types (const(GUID), void**)
		//
		hr = storage.QueryInterface(IID_IUnknown, cast(void**)&pUnk);

		//
		// Does not compile either:
		//
		// Error: GUID(0u, cast(ushort)0u, cast(ushort)0u, [cast(ubyte)192u, 
cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, 
cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)70u]) is not an lvalue
		//
		hr = storage.QueryInterface(&IID_IUnknown, cast(void**)&pUnk);
	}
}

int main(string[] argv)
{
	HRESULT hr=CoInitialize(null); // Initialize OLE
	if (FAILED(hr))
	{
		printf("OLE 2 failed to initialize\n");
		return EXIT_FAILURE;
	}

	CreateCompoundDoc("hello.doc");

	// Only call this if CoInitialize worked
	CoUninitialize();
	return EXIT_SUCCESS;
}



More information about the Digitalmars-d-learn mailing list