| View previous topic :: View next topic |
| Author |
Message |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 02, 2008 8:08 am Post subject: Message DLL to Console application. |
|
|
Hey,
how could I send a message from a dll to my console application.
The console application is using the dll already.
But I have no idea how I could do that.
Any suggestions?
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Tue Dec 02, 2008 8:42 am Post subject: |
|
|
if its only one way communication, sendmessage or postmessage is the easiest of all
if you need consant duplex communication between two or more processes, use named pipe. u can send either string type or byte type data
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 02, 2008 8:58 am Post subject: |
|
|
Yea I thought of Post/Send-Message too, but I don't know how to revice the message in the Console application then.
TranslateMessage() and DispatchMessage().
But DispatchMessage() calls the WinProc which doesn't exist in this case.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 02, 2008 9:20 am Post subject: |
|
|
Once the DLL is in the memory of the console you can call console APIs, for instance, printf, and the output will be shown on the console window, use it the same as you would've used them in the console application.
In your DLL:
| Code: | | printf("X.DLL called printf!\n"); |
Remember, you're in the process's memory.
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 02, 2008 9:41 am Post subject: |
|
|
Thanks Symbol. That makes sense x).
The problem is, that it's a dll with a system-wide hook.
So I need to send the message to a constant handle.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 02, 2008 10:23 am Post subject: |
|
|
You could also redirect the window procedure to your own window procedure:
| Code: | LONG oldWndProc = SetWindowLong(hwnd, GWL_WNDPROC, (LONG)newWndProc);
LRESULT CALLBACK myWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
...
...
}
return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam);
} |
Or simply make a window.
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Tue Dec 02, 2008 10:28 am Post subject: |
|
|
look at GetStdHandle ... ReadConsole WriteConsole so forth ;p
http:// msdn . microsoft . com/en-us/library/ms685032(VS.85).aspx
those are some good suggestions Symbol and Bizarro i feel that SendMessage accompanied by a threaded GetMessage that pools the message queue relativily slowly so as to not have a overbearing performance degradation would the best internal method.
another valid solution would be to use Indirection to write data/code directly to the process memory you could even recycle String locations ...
making a Green Application would be funneh
|
|
| Back to top |
|
 |
|