基于http://en.highscore.de/cpp/boost/smartpointers.html#smartpointers_shared_pointer
#include <boost/shared_ptr.hpp>
#include <windows.h>
int main()
{
boost::shared_ptr<void> h(OpenProcess(PROCESS_SET_INFORMATION, FALSE,
GetCurrentProcessId()), CloseHandle);
SetPriorityClass(h.get(), HIGH_PRIORITY_CLASS);
}
问题:
为什么h
定义为boost::shared_ptr<void>
而不是boost::shared_ptr<HANDLE>
?
供参考:
WINBASEAPI
HANDLE
WINAPI
OpenProcess(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in DWORD dwProcessId
);
typedef void * HANDLE;
http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/sp_techniques.html#pvoid