View Single Post
  #47 (permalink)  
Old 08-02-2007, 04:05 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Post Re: VC++ Tips & Tricks

__uuidof Operator

The __uuidof keyword retrieves the GUID attached to the expression.

__uuidof ( expression )
The expression can be a type name, pointer, reference, or array of that type, a template specialized on these types, or a variable of these types. The argument is valid as long as the compiler can use it to find the attached GUID.

A special case of this intrinsic is when either 0 or NULL is supplied as the argument. In this case, __uuidof will return a GUID made up of zeros.

Use this keyword to extract the GUID attached to:

An object by the uuid extended attribute.
A library block created with the module attribute.
The following code (compiled with ole32.lib) will display the uuid of a library block created with the module attribute:
// expre_uuidof.cpp
// compile with: ole32.lib
#include "stdio.h"
#include "windows.h"

[emitidl];
[module(name="joe")];
[export]
struct stuff {
int i;
};

int main() {
LPOLESTR lpolestr;
StringFromCLSID(__uuidof(joe), &lpolestr);
wprintf(L"%s", lpolestr);
CoTaskMemFree(lpolestr);
}
In cases where the library name is no longer in scope, you can use __LIBID_ instead of __uuidof. For example:

StringFromCLSID(__LIBID_, &lpolestr);

.................
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Reply With Quote