|
You are creating the mutex in installhook which is called from you app. The mutex handle, mutex, is not shared, so any other process that tries to access mutex (via GetMsgProc) will always get a NULL mutex.
At the begining of GetMsgProc do OpenMutex to set the "mutex" variable for that process to the acutal mutex handle.
Just a personal thing - MFC in hook DLL is a performance killer. And a pain in the arse to boot.
|
|
|
|
|
Diddy,my code is below after modified:
GetMsgProc()
{
HANDLE m_hmutex=NULL;
m_hmutex=OpenMutex(NULL,FALSE,"timemutex");
if(NULL == m_hmutex)
return CallNextHookEx(hHook, nCode,wParam, lParam);
WaitForSingleObject(m_hmutex,INFINITE);
strcpy(LastEventTimebuf,strCurTime);
ReleaseMutex(m_hmutex);
}
BOOL __declspec(dllexport)__stdcall installhook(HWND hCallProc)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
mutex=CreateMutex(NULL,FALSE,"timemutex");
if(NULL == mutex)
return FALSE;
hCallHook=hCallProc;
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc,hins,0);
return TRUE;
}
mutex is also shared,but that problem still exist.
|
|
|
|
|
Change it to:
m_hmutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"timemutex");
Also, in BOOL __declspec(dllexport)__stdcall installhook(HWND hCallProc)
Change:
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc,hins,0);
To:
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc,AfxGetInstanceHandle(),0);
If that doesn't fix it - all I can suggest is its the way you are calling the GetLastEventTime function from your EXE - how are you declaring the exported functions in the EXE? Like this:
BOOL __declspec(dllimport)__stdcall installhook(HWND hCallProc);
BOOL __declspec(dllimport)__stdcall UnHook();
BOOL __declspec(dllimport) __stdcall GetLastEventTime(char* pBuf,int size)
??
Or are you calling via loadlibray/getprocaddress?
|
|
|
|
|
#pragma data_seg(".TimeDATA")
static HWND hCallHook=NULL;
static HHOOK hHook=NULL;
static HINSTANCE hins=NULL;
static HANDLE m_hmutex=NULL;
static char LastEventTimebuf[19]="";
#pragma data_seg()
#pragma comment(linker,"/SECTION:.TimeDATA,RWS")
// CRegulardll1App construction
CRegulardll1App theApp;
CRegulardll1App::CRegulardll1App()
{
}
BOOL CRegulardll1App::InitInstance ()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return TRUE;
}
BOOL CRegulardll1App::ExitInstance ()
{
CloseHandle(m_hmutex);
return TRUE;
}
LRESULT __declspec(dllexport)__stdcall CALLBACK GetMsgProc(int nCode,WPARAM wParam,LPARAM lParam)
{
PMSG pmsg;
pmsg = (PMSG)lParam;
if (nCode >= 0)
{
if((pmsg->message==WM_KEYDOWN || (pmsg->message==WM_MOUSEMOVE)||(pmsg->message==WM_NCLBUTTONDOWN)||(pmsg->message==WM_NCLBUTTONDBLCLK)
||(pmsg->message==WM_LBUTTONDOWN)||(pmsg->message==WM_RBUTTONDOWN)||(pmsg->message==WM_RBUTTONUP)||(pmsg->message==WM_LBUTTONDBLCLK)||(pmsg->message==WM_RBUTTONDBLCLK)))
{
COleDateTime oleLogDate = COleDateTime::GetCurrentTime();
CString strCurTime = oleLogDate.Format("%Y-%m-%d %H:%M:%S");
m_hmutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"timemutex");
WaitForSingleObject(m_hmutex,INFINITE);
strcpy(LastEventTimebuf,strCurTime);
ReleaseMutex(m_hmutex);
}
}
return CallNextHookEx(hHook, nCode,wParam, lParam);
}
BOOL __declspec(dllexport)__stdcall installhook(HWND hCallProc)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_hmutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"timemutex");
hCallHook=hCallProc;
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc,AfxGetInstanceHandle(),0);
return TRUE;
}
BOOL __declspec(dllexport)__stdcall UnHook()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL unhooked = UnhookWindowsHookEx(hHook);
return TRUE;
}
BOOL __declspec(dllexport) __stdcall GetLastEventTime(char* pBuf,int size)
{
if(NULL == pBuf || size<19)
return FALSE;
else
{
WaitForSingleObject(m_hmutex,INFINITE);
CString str(LastEventTimebuf);
strcpy(pBuf,str);
ReleaseMutex(m_hmutex);
}
return TRUE;
}
Application:
HINSTANCE hinstDLL=LoadLibrary("regulardll1.dll");
if(hinstDLL)
{
typedef BOOL GetLastEventTime(char* ,int);
GetLastEventTime* p=(GetLastEventTime*)GetProcAddress(
hinstDLL, "GetLastEventTime");
if(NULL != p)
{
char buf[19]="";
if(p(buf,sizeof(buf)))//Problem happens here
{
CString str(buf);
MessageBox(hWnd,str,"",MB_OK);
}
}
}
|
|
|
|
|
Yes - because:
typedef BOOL GetLastEventTime(char* ,int);
is very different to the way GetLastEventTime is declared:
BOOL __stdcall GetLastEventTime(char* ,int);
You will be screwing up the stack when you call a __stdcall function with __cdecl calling convention (which is the default).
Change it to:
typedef BOOL __stdcall GetLastEventTime(char* ,int);
And it should work.
|
|
|
|
|
thank you very much,I have made a mistake.
|
|
|
|
|
No problem
|
|
|
|
|
Hi all;
I am building an SDI application and have used SkinMagic to provide a convenient skin to the software. It works fine but when i close the application (either by using the X on the window or by clicking 'close' in my application), i get an error after the window has closed.
The errors goes something like this:
The memory referenced @ xxx could not be 'read'.
Its due to the use of the Skinning library but i really don't know how to cut it out.
Could you please help me.
I badly need this.
Thanks
Krugger
|
|
|
|
|
Set a breakpoint in your code (F9) and launch the debugger (F5) to see what is happening
|
|
|
|
|
krugger wrote:
Could you please help me.
Have you tried e-mailing support@appspeed.com?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Debug it using Visual C++. If that does not help, then try a kernel level debugger such as Olly Debugger and SoftICE.
Kuphryn
|
|
|
|
|
Olly Rules
|
|
|
|
|
Hi all;
I am a final year student @ Uni and i'm building an SDI application for my studies.I am using a dialogbar acting as a modeless dialog with some controls scattered on it here and there.
The problem is that i need to handle these controls (e.g ListControls etc..) within another class. When i try to do so, the compilers harshly complains that the window handle is not valid. I know that Modeless dialogs do lose their handles after creation, but i really need to access the controls on the dialogbar.
Can anybody please help me,
I really need this guys.
Thank you;
Kruger
|
|
|
|
|
krugger wrote:
I know that Modeless dialogs do lose their handles after creation
normally, for modeless dialogs, you will need to have either a class variable for it ( or a global variable ) to hold it.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
when i am trying to resize my applicalion
at that time one modal dialog of my application appears on the screen and i am not able to get the focus on my dialog or application and the mouse pointer still shows the "resize" cursor.
to activate my dialog or application i have to press (alt + tab).
i think it's because there r 2 different thread and my applicacation still calls onsize() and suddenly that dialog appears.
can anyone tell me what should i do?
|
|
|
|
|
Jiten D. Gandhi wrote:
...one modal dialog of my application appears on the screen and i am not able to get the focus on my ... application
This is how modal dialogs behave. You must dismiss them before focus returns to the application.
Jiten D. Gandhi wrote:
...my applicacation still calls onsize() and suddenly that dialog appears.
can anyone tell me what should i do?
Remove the OnSize() handler and see if the problem goes away.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Why would you need to display a modal
dialog in OnSize?
Due Regards
Mahendra
|
|
|
|
|
Friends i have a simple dialog based application. There is an OK button with id IDOK. I process its click event in OnOk().
Now i want to write another application. What i want is that, i want to post message from second application to first application, telling it that its OK button gets pressed. Or in other words i dont want to click OK button of first application with mouse. Instead i want second application to tell first application that its OK button gets clicked so that first application process OnOK handler.
How can i do so ??
Imtiaz
|
|
|
|
|
Check FindWindow and SendMessage
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Papa wrote:
Check FindWindow and SendMessage
I am aware of that. What i am asking is the parameters to be passed in SendMessage()
Imtiaz
|
|
|
|
|
Find your on ok button window and send a VK_RETURN
void CMxLabView::SendKeyToWnd ( CWnd * pWnd , int virtKey )<br />
{<br />
pWnd->SetForegroundWindow() ;<br />
pWnd->SetFocus();<br />
<br />
pWnd->PostMessage ( WM_KEYDOWN , virtKey , 0 );<br />
pWnd->PostMessage ( WM_KEYUP , virtKey , 0 );<br />
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Try this:
http://www.codeproject.com/threads/sendmsg.asp
|
|
|
|
|
I have a toolbar button that I want to change dynamically to different solid blocks of colour. I can get a handle to the current image using
tbbi.dwMask = TBIF_IMAGE;
SendMessage(hTB,TB_GETBUTTONINFO,(WPARAM)TB_COLOUR,(LPARAM)&tbbi);
himl = (HIMAGELIST)SendMessage(hTB,TB_GETIMAGELIST,0,0L);
ImageList_GetImageInfo(himl,tbbi.iImage,&ii);
and I can replace the image and tell the toolbar to use the new one using
ImageList_Replace(himl,tbbi.iImage,hbm,NULL);
SendMessage(hTB,TB_CHANGEBITMAP,TB_COLOUR,MAKELPARAM(tbbi.iImage,0));
but how do I change the bitmap or create a new one? I've tried
hbm = (HBITMAP)CopyImage(ii.hbmImage,IMAGE_BITMAP,size.cx,size.cy,LR_COPYRETURNO);
selecting into a HDC, and using FillRectEx but it doesn't work. I'm using C and win32 (I don't know C++ or MFC).
Any help appreciated.
thanks
Dave Risley
|
|
|
|
|
m_imgList->Draw(pDC, 0, CPoint(rcItem.left+2, rcItem.top+2), ILD_NORMAL);
m_imgList is pointer to an CImageList
When I draw the stupid icon to display it's background is black (icons made in Visual studio I thought used that transparent green for a background unles you specifiy otherwise)
When I draw the icon using the snippet above...I get a black background...
How do I get rid of that? Do I have to add another image to my list as a mask?
How does the caption bar do it, when it's supplied only a s single icon???
Thanks
How do I print my voice mail?
|
|
|
|
|
Have you tried using the ILD_TRANSPARENT option and when creating the image list using:
m_Images.Create(X, Y, ILC_COLOR32 | ILC_MASK, 1, 500);
Then when you add an image to the list you can specify what colour is the transparent background for that image.
Roger Allen - Sonork 100.10016
Strong Sad: I am sad I am flying
Who is your favorite Strong?
|
|
|
|
|