I have a Visual Studio 2008 C++ application for Windows where I have wrapped some platform functions that take TCHAR-based parameters and therefore have both a wide-character and narrow version selected by an ifdef.
#ifdef UNICODE
#define QueryValueW QueryValue
#else
#define QueryValueA QueryValue
#endif
inline DWORD QueryValueW( HANDLE h, LPCWSTR str )
{
return ::SomeFuncW( h, 0, true, str, 0, 0 );
}
inline DWORD QueryValueA( HANDLE h, LPCSTR str )
{
return ::SomeFuncA( h, 0, true, str, 0, 0 );
}
I’d prefer to templatize this such that the compiler can automatically select the correct version of SomeFunc based on what type of string I pass in rather than an ifdef.
template< typename charT >
inline DWORD QueryValue( HANDLE h, const charT* str )
{
// Call ::SomeFuncW or ::SomeFuncA depending on the type of `charT`.
}
Does anybody have a suggestion on how this can be accomplished? Preferably without resorting to RTTI.
This?
The first version will be called unless you explicitly call it with a
LPCSTRparameter.