Pelles C forum

C language => Windows questions => Topic started by: czerny on November 22, 2008, 12:02:57 PM

Title: DEFINE_GUID()
Post by: czerny on November 22, 2008, 12:02:57 PM
Hallo,

I would like to use the macro DEFINE_GUID() but have some problems doing this.

This macro is defined in <guiddef.h>

In a header file of mine I use

#include <initguid.h>

which himself defines INITGUID and should include guiddef.h

#define INITGUID
#include <guiddef.h>

But <guiddef.h> is included prior of this with <windows.h> and is included only once.

So, what is the correct methode to use the DEFINE_GUID() macro?

czerny

Title: Re: DEFINE_GUID()
Post by: Stefan Pendl on November 22, 2008, 05:07:32 PM
Is the order of the includes as follows ???

1) #include <initguid.h>
2) #include <windows.h>

This could solve your problem.
Title: Re: DEFINE_GUID()
Post by: Synfire on November 23, 2008, 10:51:25 AM
Are you getting errors? You shouldn't...

You can order those any way you want. The reason being because of standard header notation:

Code: [Select]
#ifndef _HEADERNAME_H
#define _HEADERNAME_H

/* Your header contents here. */

#endif //_HEADERNAME_H

This notation is used throughout POC's headers (as well as most C compilers headers). This prevents the compiler from inserting the contents of a header file twice in the event it gets #included'd twice. Like in your instance. So if you wanted you could use:

Code: [Select]
#include <windows.h>
#include <initguid.h>

or as Stefan stated:

Code: [Select]
#include <initguid.h>
#include <windows.h>

And it wouldn't really matter, the first call to #include would add the contents of the file and the second would not because _GUIDDEF_H would already be defined and #ifndef _GUIDDEF_H would fail.
Title: Re: DEFINE_GUID()
Post by: czerny on November 23, 2008, 03:24:28 PM
Is the order of the includes as follows ???

1) #include <initguid.h>
2) #include <windows.h>

This could solve your problem.


Yes! You are right!
initguid.h MUST included before windows.h

Thank you

Czerny
Title: Re: DEFINE_GUID()
Post by: Synfire on November 23, 2008, 08:15:45 PM
Actually looking at the headers Stefan's right. My bad, I was confused at what you were asking.