How will I let my c# program to get data from another application?
assume that application is, for example , "Yahoo Messenger" and someone say to you "hi there" on the chatbox...
Now开发者_如何学Go, I want my c# program to read / get that data or information from "Yahoo Messenger chat box" in print it on my application? is it possible?
You will need to use visual studio tool name SPY++ for understanding the flow of win32 api.
After that refer to these link
Get text from another application.
http://www.dreamincode.net/forums/topic/66140-scraping-the-text-from-another-application-with-win32-api/
After implementing some part of the code , please repost more specific question related to programming
It will be easy if that application (Yahoo messenger for example) provides an interface (ex: COM) for other applications to access its information.
If not, you will have to go through Windows API, capturing the handle of the exact window where the text is and all.
Have you any idea what your other application is?
EDIT: Check this Yahoo Answer. Someone has asked the same question, maybe the links provided in the answer would help you: http://answers.yahoo.com/question/index?qid=20081126161509AAhr6Dz
Yahoo Answers post content:
I would suggest looking at libpurple. This is a general-purpose IM backend with Yahoo support. It's used by the Pidgin IM client, among others.
However, note that libpurple is a C++ library, so you'd have to call into native code.
If you have control over "that application" (e.g.Yahoo messenger), you can create a shared memory using winapi:
LPSECURITY_ATTRIBUTES lpAtt=NULL;
HANDLE INVALID_FILE_HANDLE=(HANDLE)0xFFFFFFFF; //Memory handle
hMapFile=::CreateFileMapping(INVALID_FILE_HANDLE,
lpAtt,PAGE_READWRITE, 0,nSize, SharedMemName);
if (hMapFile == NULL)
{
ShowSomeMessageBox("Could not create shared memory");
return NULL;
}
LPTSTR pBuf = (LPTSTR) MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS,0,0,nSize);
if(NULL==pBuf)
{
ShowSomeMessageBox("Could not create mapped view of theshared memory");
return NULL;
}
Once you have that buffer, you can write data to it using CopyMemory or whatever api.
In your C# application you can use InterOp (P-invoke) to call WinAPI:
Use: OpenFileMapping(),MapViewOfFile() etc. to open the shared memory
Use: Marshal.ReadInt32(), Marshal.StructureToPtr() etc to read the data to your C# data structures.
精彩评论