DLL变量共享的问题
如题我想搞个记录键盘的程序
但是记录的话,只能够记录当前调用DLL程序上按下的键码其他的程序上按下键码的话,他就记录不了
郁闷,找了个共享变量的方法但是调用的时候有问题。贴上代码各位帮忙看一下谢谢
程序代码:
#include <windows.h> struct inkedl { int code;//按键码 int typel;//类型 inkedl *next; }; #pragma data_seg("Shared") extern "C" inkedl *head=NULL; #pragma data_seg( ) #pragma comment( linker, "/SECTION:Shared,RWS") void create(int code,int typel=0) { inkedl *fp; inkedl *point; point=new inkedl; point->code=code; point->typel=typel; if (head==NULL) { head=point; point->next=NULL; return ; } if (head->next==NULL) { point->next=head->next; head->next=point; //head->typel=1; return ; } fp=head; for (inkedl *&mp=head;mp->next;mp=mp->next) { if (mp->next->next==NULL) { point->next=mp->next->next; mp->next->next=point; head=fp; return ; } } } extern "C" _declspec(dllexport) void sethook(); HHOOK gouzi=NULL; LRESULT CALLBACK KeyboardProc( int code, // hook code WPARAM wParam, // virtual-key code LPARAM lParam // keystroke-message information ) { if(((DWORD)lParam&0x40000000) && (HC_ACTION==code)) { switch(wParam) { case VK_NUMPAD0: create(96,0);/*MessageBox(NULL,"0","提示",0);*/break; case VK_NUMPAD1:create(97,0);break; case VK_NUMPAD2: create(98,0);break; case VK_NUMPAD3: create(99,0);break; case VK_NUMPAD4: create(100,0);break; case VK_NUMPAD5:create(101,0);break; case VK_NUMPAD6: create(102,0);break; case VK_NUMPAD7:create(103,0);break; case VK_NUMPAD8: create(104,0);break; case VK_NUMPAD9: create(105,0);break; case VK_UP: create(38,0);break; case VK_DELETE: create(46,0);break; case VK_SHIFT: create(16,0);break; case VK_MENU:create(18,0);break; case VK_CONTROL: create(17,0);break; } } // return CallNextHookEx(gouzi,code,wParam,lParam); return 0; } extern "C" _declspec(dllexport) void sethook() { gouzi=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("win32DLL.dll"),0); } extern "C" _declspec(dllexport) void playback()//链表回放 { inkedl *fp=head; if (head==NULL) { // void sethook(); //MessageBox(NULL,"0111","提示",0); } while(head) { keybd_event(head->code,KEYEVENTF_EXTENDEDKEY,0,0); keybd_event(head->code,KEYEVENTF_KEYUP,0,0); if (head->next==NULL) { head=fp; } head=head->next; } }虽然乱了点儿,我想凑合看还是没问题的吧??