|
Right, so using an "if" is correct.
What's wrong with the messaging? How are you identifying which thread/window to send messages between processes?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I know nothing about threads yet.
I identify the window of the app to send the message to using FindWindow. I do that at the start of the program before the message loop starts but after the form has been created. Then I send a message to the window and the message contains the handle of the form in my C++ program. The app receiving the message displays the handle in a label so I can see it's worked ok. Then on the other app I have a button, when I click the button to test sending a message back a message is sent back to the C++ app using the window handle that was given. My C++ app recieves the massage ok every time I press the button. But if I set a global int to some value, say 7, when I receive the message, and in my main loop I send a message back if the int is some value, say 7, then the message is sent ok but no more messages are received in my winproc although the other app thinks they are sent ok but the return value is zero whereas in my winproc function I return 76.
My main loop is like this, modified so that it continually loops and doesn't hang waiting for a message. Maybe this is a bad idea?
<pre> // Main message loop:
while (1)
{ switch (msgin)
{ case 7:
SendMessage(hAuWiiWin,wiimsg,4,6);//4, 6 has no signifance at moment, just a test
msgin = 0;
//break;//seems break not allowed on last case?
}
if (PeekMessage(&msg,NULL,0,0,0))//so loop will continue if no msg
{GetMessage(&msg,NULL,0,0);
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Sleep(20);//don't know if this is good idea
}
</pre>
My winproc is like this
<pre>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
if (message == wiToMeCommand)
{
//ignore lParam, wParam for moment
msgin = 7;//set global int which is checked in main loop
//SendMessage(hMyWind,WM_CLOSE,0,0);//that works and this app closes
return 76;//just some value to indicate we got the msg
}
else
switch (message)
{
case WM_COMMAND:</pre>
|
|
|
|
|
You should not be using SendMessage() inside your main message loop. The message loop (or pump) is just used to receive messages from the outside world and dispatch them to your message handling code inside your WndProc() procedure. Your scenario should be something like:
If SEND button is pressed
Then
SendMessage(destWnd, myPrivateMessage, ...
End If
If other message ...
Then
Take action as necessary
If myPrivateMessage is received
Then
Do whatever ...
Endif
If other ... etc
All this code should be in the WndProc() functions which will only get invoked when a message is dispatched from the message loop.
The best things in life are not things.
|
|
|
|
|
Thanks for your reply.
I changed it as you described and I have now got things to work.
The reason I could only receive a message once weas due to an error in the app sending the message and which uses a language I am very familiar with. Because I don't have a clue what I'm doing in C++ I was looking for the problem in the C++ code!!
Thanks to all who replied.
|
|
|
|
|
Hi!!
I want to write a password program that asks for a password before win os boots.
even before windows prompts for password.
and then if password is correct it boots windows.. if wrong password is entered it again asks for password.
I dont wanna use CMOS password.. After the user is asked to select the OS from boot manager, the password should be asked for n then is correct password is entered, the os boots otherwise it asks for password again.
|
|
|
|
|
Think about this: if Windows has not been booted then how will your program run? Do you have the skills to write a self-loading program that can handle memory, keyboard input, screen output etc?
The best things in life are not things.
|
|
|
|
|
You mean, you want to write a boot loader? That's out of the scope of discussion for a forum thread like this (this board is specific for asking questions on C/C++/MFC). Google on the said topic though, and you may find something that might help you.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Yep, boot loader is the only way to do it.
|
|
|
|
|
I guess boot manager is responsible for loading the OS files...
After the user has selected the preferred OS to boot, My program is executed..
If there is list of files that the OS loads into memory before prompting the user for password(Windows' original password), I want my program to be included into this list as the second last program to be executed..
Can i do so???
|
|
|
|
|
By that time you will have reached the Windows login prompt so there seems little point. Why do you want to duplicate what is already available in a standard Windows configuration?
The best things in life are not things.
|
|
|
|
|
i want to use my password program before win os prompts for password...
|
|
|
|
|
Hi,
Yes there is a list of native applications that execute before session manager,winlogon. You can find the list in the registry at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute
There is an article here on codeproject that covers the native application subject fairly well.
Three Steps Down the Stairs: From Win32 User-Land through Native API to Kernel[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for that... it'll surely help...
|
|
|
|
|
A word of caution:
While this is surely doable, you should take care that your password program doesn't accidentally lock out a user who forgot his password. Since this is to run before the windows logon, 'user' in this case means everyone!. Are you really sure you want to run this before the windows logon? I mean, if a user forgets his windows password, an administrator can still log on using his own password, and reset the users password for him. But if your program fails, how then will you ever get back on your machine?
|
|
|
|
|
Thanks... Will surely take care of it... Thanks for this scenario...
|
|
|
|
|
Do you mean like writing your own gina.dll (or the replacement process post-vista)
See:http://msdn.microsoft.com/en-ca/magazine/cc163489.aspx[^]
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
listen go to bios setting and there is a hardware password option select it and then give the password which u feel like and save and exit . The next time you boot in first u will have to enter password and your windows will boot.try it i have done it
|
|
|
|
|
DO u know this password can be bypassed... I've bypassed this password so many times... Thats why i dont want to use it..
|
|
|
|
|
I have a structure, suppose USER_INFO. When my program starts it serializes this structure from an archive file. My program uses these values, modifies few of them and when my program exists it serializes all values to that file again which it can read again on next start up. This way I stores the state of the application.
Now the problem is that when I add a new field (or structure member variable) to structure. It can not read the old values from the file because structure size is now changed. I want a solution to overcome this problem. Currently an alternative way which I am using is introducing a new structure, read the old data in old structure, copy old data from old structure to new structure and write the new structure to the file. But it is not a good solution. Can Sqlite db give a better solution because adding a new filed in db is not a big problem?
|
|
|
|
|
Are you using MFC?
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
|
|
Looks like it can be helpful. I can specify schema version in that and at them time of reading I can check for the schema version. However I was storing whole cmap<cstring, structure=""> into file. I am not using << or >> operators to read and write each element one by one. So using schema version I can detect version but still I need to create another structure to load new schema version data while old schema data can be loaded into old structure. I want a solution in which I can read old schema data into new structures. So that I don't have to keep both structure versions in code. It should eliminate copying from one structure(old structure) to another structure(new structure).
|
|
|
|
|
My cmap is like
cmap<CString, LPCTSTR, STRUCT_USER_INFO, STRUCT_USER_INFO&>
writing to file like this
CFile file;
file.Open(pApp->AppFolderPath + "\\my_archive_file", CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
CArchive ar(&file, CArchive::store);
pApp->cmap_st_user_info.Serialize(ar);
ar.Close();
file.Close();
|
|
|
|
|
The only problem I see is the non-portability of writing the structure to the file instead of individual items. That is compiler structure [type] alignment dependent and may change from one compiler to the next or one version of the compiler to the next.
Your solution sounds like a simple application of the KISS principle and avoids the problems of more complex solutions. Just add a header of some kind to the file. The header should contain an identifier, marking the file as the correct type, and a version number indicating the format type (a.k.a. data type [structure type]). This also has the advantage of being cross-language and cross-platform supportable.
It sounds like all the data is read into memory at start up. In that case you only need one method (function) to read the file and convert it to the internal data structure at start up and one for writing it (if it has changed) out when shutting down.
I used the above method in a commercial application (originally written in C) that supports file formats going back over 20 years. This is comparable to reading and writing Word or other document types that contain version specific format support.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|