// OsdDll.cpp : Defines the initialization routines for the DLL.
//#include "stdafx.h"
#include "OsdDll.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endifHHOOK  g_Hook = NULL;
HWND   hwndAfter   =   NULL;   
DWORD  g_oldDate=0;LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam);
void SaveLog(char* c);
//
//TODO: If this DLL is dynamically linked against the MFC DLLs,
// any functions exported from this DLL which call into
// MFC must have the AFX_MANAGE_STATE macro added at the
// very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC.  This means that
// it must appear as the first statement within the 
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//// COsdDllAppBEGIN_MESSAGE_MAP(COsdDllApp, CWinApp)
END_MESSAGE_MAP()
// COsdDllApp constructionCOsdDllApp::COsdDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only COsdDllApp objectCOsdDllApp theApp;
// COsdDllApp initializationBOOL COsdDllApp::InitInstance()
{
CWinApp::InitInstance(); return TRUE;
}DllExport void WINAPI InstallLaunchEv(HWND hwnd)
{
g_Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LauncherHook,GetModuleHandle(NULL),0);
hwndAfter=hwnd;
}DllExport void WINAPI UnInstallLaunchEv()
{
//DllCanUnloadNow();
UnhookWindowsHookEx(g_Hook);
}LRESULT CALLBACK LauncherHook(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT Result=CallNextHookEx(g_Hook,nCode,wParam,lParam);
#ifdef _DEBUG
switch(wParam)
{
case WM_KEYDOWN:
TRACE("\r\nFist===>%s nCode==>%x\r\n","WM_KEYDOWN",nCode);
break;
case WM_KEYUP:
TRACE("\r\nFist===>%s nCode==>%x\r\n","WM_KEYUP",nCode);
break;
case WM_SYSKEYDOWN:
TRACE("\r\nFist===>%s nCode==>%x\r\n","WM_SYSKEYDOWN",nCode);
break;
case WM_SYSKEYUP:
TRACE("\r\nFist===>%s nCode==>%x\r\n","WM_SYSKEYUP",nCode);
break;
}
#endif //_DEBUG if(nCode==HC_ACTION)
{
PKBDLLHOOKSTRUCT p=(PKBDLLHOOKSTRUCT)lParam;
DWORD current_date=0;
TRACE("Hot Key==>%s ==>%x\r\n",wParam==0x100||wParam==0x104?"PressDown":"Not PressDown",p->vkCode);
switch(wParam)
{
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_KEYUP:    
case WM_KEYDOWN: 
switch(p->vkCode)
{
case VK_VOLUME_MUTE :
TRACE("result ==>VK_VOLUME_MUTE\r\n");
::SendMessage(hwndAfter,WM_VOLUME_MUTE,Volume_Mute,0);
break;
case VK_VOLUME_DOWN :
TRACE("result ==>VK_VOLUME_DOWN\r\n");
::SendMessage(hwndAfter,WM_VOLUME_DOWN,Volume_Down,0);
break;
case VK_VOLUME_UP :
TRACE("result ==>VK_VOLUME_UP\r\n");
::SendMessage(hwndAfter,WM_VOLUME_UP,Volume_Up,0);
break;
case 0x6d:
case 0xba: 
current_date=GetTickCount();
if (current_date-g_oldDate>=400)
{
g_oldDate=current_date;
TRACE("result <==>      ");
::PostMessage(hwndAfter,WM_HOTKEY_PRESS,2,0);
}
else
TRACE("=============>ERROR    \r\n");
break;
default:
break;
}
break;
default:
break;
}
}
return Result;
}void SaveLog(char* c)
{
CTime tm=CTime::GetCurrentTime();
CString name;
name.Format(_T("c:\\Key_%d_%d.log"),tm.GetMonth(),tm.GetDay());
CFile file;
if(!file.Open(name,CFile::modeReadWrite))
{
file.Open(name,CFile::modeCreate|CFile::modeReadWrite);
}
file.SeekToEnd();
file.Write(c,sizeof(c));
file.Close();

解决方案 »

  1.   

    错误
    file.Write(c,sizeof(c));use string length  (strlen)
      

  2.   

    补充下            case 0x6d:
                case 0xba:
    这个地方会去读笔记本的EC,如果这两个中的一个狂来的话
    hook就失效了,键盘的所有按键全没有了,必须要重安装HOOK就可以,谁能帮我解释下为什么PS: 如果我不做读EC的动作,就没问题,,,,。
    狂郁闷中,追了好几天了
      

  3.   


    最后再说一下,最那个FUNCTION是没有使用的,是以前学做DLL的时候,在网上载的代码中的,那代码从来没有使用的,不要研究那个代码
      

  4.   

    错误
    file.Write(c,sizeof(c));use string length (strlen)