Wednesday, 28 August 2013

Template class to close HANDLES and other WINAPI's?

Template class to close HANDLES and other WINAPI's?

I'm new to C++ and need some help.
I want to make a template class/struct that handles HANDLE and other
WINAPIs so far is this code:
template <typename type_to_open, typename returntype, returntype (WINAPI *
GlobalFn)(
type_to_open )> class Handle_Wrap {
public:
type_to_open data;
Handle_Wrap (type_to_open in_data) { data = in_data; }
~Handle_Wrap() { returntype (WINAPI * GlobalFn)( type_to_open );}
};
Handle_Wrap <HANDLE, BOOL, ::FindClose> hFind ( FindFirstFileA
(pattern.c_str(), &ffd) );
I honestly don't think that its working and the compiler gives me a warning:
warning C4101: 'GlobalFn' : unreferenced local variable
I saw this code from the web and did some changes to it, and i don't know
if this is the right way to do it?

No comments:

Post a Comment