Click here to Skip to main content
15,920,503 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c++ win32, SQL Server Connection, which one? Pin
jkirkerx30-Nov-11 7:50
professionaljkirkerx30-Nov-11 7:50 
Questionto send message to console exe Pin
zon_cpp26-Nov-11 22:16
zon_cpp26-Nov-11 22:16 
AnswerRe: to send message to console exe Pin
Richard MacCutchan26-Nov-11 22:18
mveRichard MacCutchan26-Nov-11 22:18 
AnswerRe: to send message to console exe Pin
Erudite_Eric26-Nov-11 22:22
Erudite_Eric26-Nov-11 22:22 
AnswerRe: to send message to console exe Pin
Rajesh R Subramanian26-Nov-11 22:25
professionalRajesh R Subramanian26-Nov-11 22:25 
AnswerRe: to send message to console exe Pin
CPallini26-Nov-11 22:39
mveCPallini26-Nov-11 22:39 
AnswerRe: to send message to console exe Pin
Chuck O'Toole27-Nov-11 5:28
Chuck O'Toole27-Nov-11 5:28 
AnswerRe: to send message to console exe Pin
Randor 27-Nov-11 5:52
professional Randor 27-Nov-11 5:52 
Hi,

For some reason I have been seeing this question alot... and the adequate responses. Although it is correct that console applications initially do not have a message queue... the first time a win32k.sys/GDI syscall greater or equal to 0x1000 is invoked... the windows kernel increases the thread stack-size and invokes KiConvertToGuiThread which will convert the console thread into a GUI thread with a message queue.

How do you 'invoke a system call above 0x1000' ?

WIN32K.SYS System Call Table[^]

As you can see in that table... the first GDI system call NtGdiAbortDoc is at index 0x1000. Because we know that the GetMessage function[^] results in a call to NtUserGetMessage and the DispatchMessage function[^] results in a call to NtUserDispatchMessage. We can infer that by simply creating a message loop... we will have in-fact promoted the thread into a GUI thread.

In other words... by simply attempting to pump the message queue... the thread is given one.

C++
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
	TranslateMessage(&msg);
	DispatchMessage(&msg);
}


So what do you have now? Now you have a console process with a thread containing a message queue that has no window HANDLE so cannot recieve window messages. Is this the end of the road?

No, window messages are not the only type of message. You can still use the PostThreadMessage function[^] to post thread messages to the console.

Step 1: Create two console applications... Sender and Reciever.
Step 2: In the reciever begin an infinite message pump (console thread will be promoted to gui thread by the subsystem)
Step 3: In the sender call CreateProcess with the CREATE_NEW_CONSOLE flag that creates the reciever process. (otherwise messages will appear in senders console!)
Step 4: Using the PROCESS_INFORMATION.dwThreadId begin posting messages with PostThreadMessage to reciever from sender.

Best Wishes,
-David Delaune
GeneralRe: to send message to console exe Pin
CPallini27-Nov-11 6:01
mveCPallini27-Nov-11 6:01 
GeneralRe: to send message to console exe Pin
Erudite_Eric27-Nov-11 6:57
Erudite_Eric27-Nov-11 6:57 
QuestionRe: to send message to console exe Pin
Randor 27-Nov-11 7:49
professional Randor 27-Nov-11 7:49 
GeneralRe: to send message to console exe Pin
Software_Developer27-Nov-11 8:56
Software_Developer27-Nov-11 8:56 
GeneralRe: to send message to console exe Pin
Randor 27-Nov-11 9:06
professional Randor 27-Nov-11 9:06 
GeneralRe: to send message to console exe Pin
Richard Andrew x6427-Nov-11 9:57
professionalRichard Andrew x6427-Nov-11 9:57 
GeneralRe: to send message to console exe Pin
Randor 27-Nov-11 11:15
professional Randor 27-Nov-11 11:15 
GeneralRe: to send message to console exe Pin
Albert Holguin28-Nov-11 7:46
professionalAlbert Holguin28-Nov-11 7:46 
AnswerRe: to send message to console exe Pin
Software_Developer27-Nov-11 7:46
Software_Developer27-Nov-11 7:46 
AnswerRe: to send message to console exe Pin
David Crow27-Nov-11 11:03
David Crow27-Nov-11 11:03 
QuestionDifferent GUI rendereng between WinXP and Vista-Win7 Pin
Bram van Kampen26-Nov-11 14:38
Bram van Kampen26-Nov-11 14:38 
Questionhow to read a character array line by line in C? Pin
robin70025-Nov-11 14:38
robin70025-Nov-11 14:38 
AnswerRe: how to read a character array line by line in C? Pin
robin70025-Nov-11 18:49
robin70025-Nov-11 18:49 
GeneralRe: how to read a character array line by line in C? Pin
enhzflep25-Nov-11 21:35
enhzflep25-Nov-11 21:35 
AnswerRe: how to read a character array line by line in C? Pin
Richard MacCutchan25-Nov-11 22:24
mveRichard MacCutchan25-Nov-11 22:24 
AnswerRe: how to read a character array line by line in C? Pin
CPallini26-Nov-11 0:45
mveCPallini26-Nov-11 0:45 
GeneralRe: how to read a character array line by line in C? Pin
enhzflep26-Nov-11 0:59
enhzflep26-Nov-11 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.