|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - template implements __uuidof
I implements MSC++ keyword __uuid partly with template.
It May be usefull to port ATL and lastest MFC library to DMC++.
The source code.
#include <ole2.h> //for type REFIID ...
template <typename T> struct UUID_Traits;
#define DEFINE_IID_TRAITS(interface) \
template<> struct UUID_Traits<interface>\
{\
static REFIID GetIID()\
{\
return IID_ ## interface;\
}\
};
DEFINE_IID_TRAITS(IUnknown)
DEFINE_IID_TRAITS(IDispatch)
template <typename T> inline
REFIID uuidof(T&)
{
return UUID_Traits<T>::GetIID();
}
template <typename T> inline
REFIID uuidof(T*)
{
return UUID_Traits<T>::GetIID();
}
//-0------testing------0-
#include <stdio.h>
void print_iid(REFIID riid)
{
LPOLESTR test;
StringFromCLSID(riid, &test);
printf("%ws\n", test);
CoTaskMemFree(test);
}
int main()
{
CoInitialize(0);
IDispatch* p1;
IUnknown& p = *p1;
print_iid(uuidof(p));
print_iid(uuidof(p1));
CoUninitialize();
}
Feb 01 2005
COMSTL has had this for several years, in the form of its IID_traits<> class template, where it forms an integral part of the interface_cast<> mechanisms. It also resolves to using __uuidof on compilers that support it. See comstl_interface_cast.h, comstl_interface_traits.h & comstl_interface_traits_std.h The full technique's explained in detail in Chapter 19 of my book, Imperfect C++ (http://www.awprofessional.com/titles/0321228774/). Cheers Matthew Wilson Author: "Imperfect C++", Addison-Wesley, 2004 (http://www.imperfectcplusplus.com) Contributing editor, C/C++ Users Journal (http://www.synesis.com.au/articles.html#columns) STLSoft moderator (http://www.stlsoft.org) ------------------------------------------------------------------------------- "So far, C++ is the best language I've discovered to say what I want to say" -- Alex Stepanov ------------------------------------------------------------------------------- <nyra sohu.com> wrote in message news:ctpu8p$2bqr$1 digitaldaemon.com... Feb 02 2005
|