15,905,914 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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...