Click here to Skip to main content
15,905,914 members

Comments by bikramthapa (Top 4 by date)

bikramthapa 13-Jul-11 21:30pm View    
Hi KarstenK,
Thanks for ur input, but I had resolve that issue already. Please check my reply to "Rage" : Is the issue then solved ?
Can u please suggest some ideas.

Regards
Bikram...
bikramthapa 13-Jul-11 21:26pm View    
Hi Rage,
I did the GetLastError() and found that for openclipboard() the handle was invalid. The reason being inside my hooked function, I cannot access the clipboard. So from inside my dll I pass commandline to my dialog box.
FORWARD_WM_COPYDATA(hdlMl1, , NULL, &cds, SendMessage);

//This is a GetClipboardData replacement function inside dll
HANDLE WINAPI Hook_GetClipboardData(UINT uType)
{
......
//Check if notepad or wordpad
if(_tcsicmp(allowedAppName, szProcessPathname) == 0)//If user allowed app send info to change value of clipboard
{
HANDLE nResult = ((PFNGETCLIPBOARDDATA)(PROC) g_GetClipboardData)(uType); //original hooked fn called.
//now call the openclipboard to set custom data in clipboard.
//This call fails
if(OpenClipboard(NULL)){ //this call fails
.....
}
//So used this technique
COPYDATASTRUCT cds = { 0, ((DWORD)_tcslen(pszDest) + 1) * sizeof(TCHAR), pszDest};
FORWARD_WM_COPYDATA(hdlMsWheel1, NULL, &cds, SendMessage);//send message to mfc client app
}
}


Then inside my dialobox I use wm_copydata in my messagemap.
The procedure to handle is
//Window Procedure to grab command line argument if program already running
LRESULT CKlipboardControllerDlg::OnCopyData(WPARAM wParam, LPARAM lParam)
{
......
COPYDATASTRUCT* pCDS = reinterpret_cast<copydatastruct*>(lParam);
TCHAR* pszCmdLine = static_cast<tchar*>(pCDS->lpData);
//SendMessage will always fail the openclipboard()
PostMessage(WM_COMMAND,IDC_BUTTON_HIDDEN,0);//simulate hidden button click
....
}

void CKlipboardControllerDlg::OnBnClickedButtonHidden()
{
// TODO: Add your control notification handler code here
if(stepCount == 2)//check how many times call from dll was made
{
if(OpenClipboard()){
....//set new data
}
}
}

The results are unreliable. If say I have two strings 346456 and 454. If I do paste operation in quick succession, the result should first print first string followed by second string and third time the clipboard should not print any thing. But sometimes first string is printed twice , other times second string is printed more than once etc. Because I do the post call to reset clipboard content, the stepCount variable has old value while the second call has been made.
How can I do a post message to call any method inside my dll instead of passing commandline to client application.
My second option would be to make stepCount variable thread safe, I tried critical section but no luck. stepCount is int member variable of my dialogbox class. Can u suggest means to make postmessage calls to this variable lock while its inside the the function CKlipboardControllerDlg::OnBnClickedButtonHidden();

Thanks
Bikram...
bikramthapa 6-Jul-11 16:12pm View    
Hi TRK3,
Ya, my mistake, I should have done that. Here is the link to the project example I used:http://www.wintellect.com/Downloads/Windows%20via%20C++%20Code%20(December%201,%202007).zip The projects are 22-LastMsgBoxInfo and 22-LastMsgBoxInfoLib.
The solution to the problem posted by me earlier simply involved having correct function name and function prototype, so I thought that won't be relevant to current issue. But yes, I should have posted the link to the sample code. Sorry for that.

Regards
Bikram...
bikramthapa 4-Jul-11 15:18pm View    
Hi SAKryukov,
Here is the link to the project example I used.
http://www.wintellect.com/Downloads/Windows%20via%20C++%20Code%20(December%201,%202007).zip
The project are 22-LastMsgBoxInfo and 22-LastMsgBoxInfoLib. The sample code works, so, I simply modified the code example to replace MessageBox with SetClipboardData and GetClipboardData.
I put Messagebox("Replacement Function Called") in the SetClipboardData and GetClipboardData replacement functions, so that I know my code is getting called when clipboard content is changed or accessed.
My idea is that the two clip board functions are not getting hooked. So what ever copy paste I do after I load the dll in my app, the two replacement functions never get called.
I am using VS 2005 pro sp1 with latest Platform SDK on Windows XP SP3 machine. The purpose of my task is to make sure that when my app runs; The clipboard content can only be copied to list of app I have. Also I dont want to use SetClipboardViewer or similar technique as it does not fulfill my need.

I would really appreciate if you can provide any help.

Thanks
Bikram...