Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

Questin about #define use

In this source code:

http://support.microsoft.com/?kbid=171907

what is the effect of the lines

#define INITGUID


#define USES_IID_IMessage
0
jjacksn
Asked:
jjacksn
  • 4
  • 2
  • 2
  • +1
1 Solution
 
jkrCommented:
#define INITGUID

tells the compiler to pull in the actual variable definitions for the GUIDS used. Since the declarations can and in fact are used over many compilation units (aka .cpp files), reserving space for them in each of them would be a waste of memory and - even worse - result in a linker error about multiply defined symbols. So, only one .cpp file will define that, and additionaly it has to be ensured that at least one does. 'USES_IID_IMessage' serves the same purpose.
0
 
jjacksnAuthor Commented:
I see, thanks.  I'm unfourtunately getting compilation errors:

OutlookCOM error LNK2001: unresolved external symbol _CLSID_MailMessage
OutlookCOM error LNK2001: unresolved external symbol _IID_IMessage

Where CLSID_MailMessage is defined in that source code as

DEFINE_GUID(CLSID_MailMessage,
0x00020D0B,
0x0000, 0x0000, 0xC0, 0x00, 0x0, 0x00, 0x0, 0x00, 0x00, 0x46);

in mapiguid.h there is the code

#if !defined(INITGUID) || defined(USES_IID_IMessage)
DEFINE_OLEGUID(IID_IMessage,            0x00020307, 0, 0);

Both of the macros DEFINE_GUID and DEFINE_OLEGUID are called at the tope of my .cpp source file These vars are then referenced inside a class method in the same .cpp file.
0
 
jkrCommented:
Are you linking with uuid.lib and the MAPI libs?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jjacksnAuthor Commented:
Yeah, I'm linked to mapi32.lib and uuid.lib

why is their an underscore infront of the var name?
0
 
AxterCommented:
The compiler adds an underscore to the name when its trying to look for unresoved external symbols.

Have you downloaded the latest SDK?

You may be getting this error because you don't have the latest SDK loaded.

You can get the latest SDK free from MS web site.
0
 
AxterCommented:
You can download the latest platform SDK from the following link:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/ 
0
 
jjacksnAuthor Commented:
I do that the latest SDK updates installed.
0
 
itsmeandnobodyelseCommented:
See the answer to

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20970112.html

Maybe, it already answers your question sufficiently, but i will try to give some more details:

In system header objbase.h there is the following code sequence

//-------------------------------------------------------------------------------------
#ifndef INITGUID
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
    EXTERN_C const GUID FAR name
#else

#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
        EXTERN_C const GUID name \
                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
#endif // INITGUID
//------------------------------------------------------------------------------------------

You could see, that there are two different definitions of the macro DEFINE_GUID dependend on the definition of the macro INITGUID. IF INITGUID is defined with DEFINE_GUID you only declare an extern variable. An extern variable can be used in a C or C++ variable as any other global variable however the linker expects that there is exactly an object module where the variable not only is declared as extern but defined, that means that a storage is assigned to that variable. In objbase.h the first definition declares the variable as extern and the second definition defines it (in the #else branch). Therefore in your project there must be exactly one CPP file that includes objbase.h while INITGUID isn't defined. All other CPP files _MUST_ have a #define INITGUID if  using macro DEFINE_GUID or DEFINE_OLEGUID before including any system headers. Otherwise, you would get a linker error that the variable _CLSID_MailMessage is duplicate defined.

Look at that comment that is in objbase.h above that definitions:

//------------------------------------------------------------------------------------------
// macros to define byte pattern for a GUID.
//      Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
//
// Each dll/exe must initialize the GUIDs once.  This is done in one of
// two ways.  If you are not using precompiled headers for the file(s) which
// initializes the GUIDs, define INITGUID before including objbase.h.  This
// is how OLE builds the initialized versions of the GUIDs which are included
// in ole2.lib.  The GUIDs in ole2.lib are all defined in the same text
// segment GUID_TEXT.
//
// The alternative (which some versions of the compiler don't handle properly;
// they wind up with the initialized GUIDs in a data, not a text segment),
// is to use a precompiled version of objbase.h and then include initguid.h
// after objbase.h followed by one or more of the guid defintion files.

//------------------------------------------------------------------------------------------

What i mean to be able to learn from that comment is that for a Wizard defined project that uses Precompiled Header Files, the include file stdafx.h does the job for you by defining INITGUID. However, i couldn't spot from this, where the GUIDs get defined.

Hope that helps,
Alex
 
0
 
jjacksnAuthor Commented:
Alex, I'm pretty sure that's it, I'll be back in the office on Monday to check it out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now