thus i use MFC service ,you can write code such as //启动服务 void CServiceApp :: Run( DWORD, LPTSTR *) { // args not used in this small example // report to the SCM that we're about to start ReportStatus(SERVICE_START_PENDING); m_hStop = ::CreateEvent(0, TRUE, FALSE, 0); // You might do some more initialization here. // Parameter processing for instance ... //this you can Load your hook here VERIFY(m_hInstance=::LoadLibrary((LPCTSTR)"test.dll")); FUNC_INSHOOK pFuncsethook; //install shell hook in process VERIFY(pFuncsethook=(FUNC_INSHOOK)::GetProcAddress(m_hInstance,"installkeyhook")); pFuncsethook();//install keyboard Hook }
http://www.codeguru.com/system/nt_service.shtml
//启动服务
void CServiceApp :: Run( DWORD, LPTSTR *)
{ // args not used in this small example
// report to the SCM that we're about to start
ReportStatus(SERVICE_START_PENDING);
m_hStop = ::CreateEvent(0, TRUE, FALSE, 0); // You might do some more initialization here.
// Parameter processing for instance ...
//this you can Load your hook here
VERIFY(m_hInstance=::LoadLibrary((LPCTSTR)"test.dll"));
FUNC_INSHOOK pFuncsethook;
//install shell hook in process
VERIFY(pFuncsethook=(FUNC_INSHOOK)::GetProcAddress(m_hInstance,"installkeyhook"));
pFuncsethook();//install keyboard Hook
}