|
baerten wrote: DOS-Application
if you mean is a console application, yes its possible...
|
|
|
|
|
Yes, it's a console application
Need i to launch a thread where i instantiate a class which has a message loop?
And all messages where handled into this class...
Thanks for your help
|
|
|
|
|
No need of seperate thread. All you have to do is to create a window and below that you can write the message loop.
|
|
|
|
|
There is no need to crate a window to have a message loop. Just put one in and it will work fine.
Steve
|
|
|
|
|
at the main function of the console application i start a new thread via AfxBeginThread
In the function, which will be started from AfxBeginThread i used this code:
MSG msg;
while(1) {
if(::PeekMessage(&msg,hWndofTheConsole,0,0,PM_REMOVE)) {
printf("I GOT A MESSAGE");
if(msg.message == WM_USER+55) ..............
}
}
But i receive no message, even not he OnKeyDown Messages
An MFC Program opens this Console Application via CreateProcess
I can send keystrokes from out the MFC-Applic to the Console and there, the letters will be entered.
So the WM_KEYDOWN Messages will arrive correcly the console
I tested also the hWndofTheConsole, i performed a ShowWindow(hWndofTheConsole,SW_SHOW/SW_HIDE)
and the console appears and disappears, so the HWND is correct.
But, why i can't catch the messages
Thanks for your help you two
|
|
|
|
|
Are you wanting the console application to receive input from the GUI application? If so, see here and here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Stephen Hewitt wrote: There is no need to crate a window to have a message loop. Just put one in and it will work fine.
I doubt this is because of the console window in the main thread. How ever I dont think a simmple message loop will work in a new thread, unless window is created.
|
|
|
|
|
You don't need a window to have a message loop. The existence of the PostThreadMessage[^] function should hint at this: it sends a message but takes no window handle. The simple test application which follows proves the point:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <conio.h>
int main(int argc, char* argv[])
{
using namespace std;
DWORD idUs = GetCurrentThreadId();
PostThreadMessage(idUs, WM_APP, 0, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_APP)
{
cout << "Got message but have no window!" << endl;
PostQuitMessage(0);
}
}
cout << "Press any key...";
_getch();
return 0;
}
In short: messages are sent to threads or windows (and windows are always ownded by a particulat thread) ; message pumps process messages for a particular thread.
Steve
|
|
|
|
|
I set the loop with ::PeekMessage into the main_function, but no effect
How do you mean "create a new window to add a message loop" to create a simple CDialog-derived window ?
In this case the dialog has a new Handle and the MFC Application sends the messages to the process/main-thread, so the messages don't travel to the dialog, or?
All this work to transmit two int's to another process
I think i will write the int-values as text and the Console reads the values, that's very stupid,
but works
|
|
|
|
|
I think its hard to get the messages of a console window. I am not sure but i think you can try hooking( SetWindowsHookEx() ).
|
|
|
|
|
Try here[^]; this section of Code Project deals with inter-process communication. There are easier ways to pass data between processes than the Windows message mechanism, especially when both of the apps aren't windowed applications.
Software Zen: delete this;
|
|
|
|
|
|
convert cstring to const unsigned short *
How can i achieve this??
|
|
|
|
|
This is a really bad idea. A CString is an object representing a memory area in the PC. You can interpret to a pointer BUT it should be temporary. => (LPCSTR).
(const unsigned short *)(LPCSTR)
But there is no unsigned short !!!!
RTFM
Greetings from Germany
|
|
|
|
|
VARIANT v;
First case:
v.bstrVal = SysAllocString(sz);
//where sz is a OLECHAR FAR*
Second case:
v.bstrVal =sz.AllocSysString();
//where sz is a CString
Second case solved my problem
|
|
|
|
|
The right decription is often half of the solution of the problem!!!
For these String conversion are some API function and macros available. Its better to use them.
I dont need them often so I dont remember gut I guess like OLE2CHAR( )
Greetings from Germany
|
|
|
|
|
yashveer wrote: v.bstrVal =sz.AllocSysString();
dont forget to free it using the SysFreeString().
|
|
|
|
|
ya i m actually using
SysFreeString()
I wouldnt have known about all this. I was searching for a way to convert text to csv.... i found something on msdn online
http://support.microsoft.com/kb/179706/
Instead of fixed string given in the code:
FillSafeArray(L"John", 0, 0, &saRet);
I wanted to use the following:
FillSafeArray(str, 0, 0, &saRet);
where str is CString
and hence....all this
|
|
|
|
|
Use the MultiByteToWideChar() function.
Other option is to define the _UNICODE in the project setting preprocessor definitions, so that the CString will be keeping wide characters internally and hence no conversion is requirent
|
|
|
|
|
You can use MultiByteToWideChar may be somethng like this
CString str;
wchar_t* wch
MultiByteToWideChar(CP_ACP,0,str,strlen(str),wch,strlen(str),NULL,NULL)
Don't forget to allocate memory to this wchar variable
then typecast this wchar to unsigned short*
FillSafeArray((unsigned short*)wch ,....)
I think this will help u out !!!
|
|
|
|
|
typecast it to const unsigned short* .....
FillSafeArray((const unsigned short*).....
|
|
|
|
|
hi all
can anybody tell me is whats the difference between UTF-8 and multibyte.
and from where i can find more information on the same?
Thanx in advance.
|
|
|
|
|
Google for "UTF-8 multibyte" and you will get many hits. Try Wikipedia first.
|
|
|
|
|
UTF-8 is a Unicode encoding scheme.
Multibyte is a common name for a number of legacy encodings that typically store strings in char arrays (in C) as opposed to wchar_t arrays.
|
|
|
|
|
Nemanja Trifunovic wrote: Multibyte is a common name for a number of legacy encodings that typically store strings in char arrays
Thus in the sense of your definition UTF-8 is a multibyte-format.
UTF-16 (not that someone in his right mind would use that) isn't.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|