String table
-
Is there anyway at runtime to add a string into the string table? What I am trying to do is have a thread load a string to the string table, then use postmessage back to the main thread. Inside of the main thread message handler I want to pop up a warning dialog that will display the string I added to the string table. Is this viable, if not what other approaches could I use?
-
Is there anyway at runtime to add a string into the string table? What I am trying to do is have a thread load a string to the string table, then use postmessage back to the main thread. Inside of the main thread message handler I want to pop up a warning dialog that will display the string I added to the string table. Is this viable, if not what other approaches could I use?
What you're asking is not viable really. Remember that string resources are embedded in the executable, thus adding a string at runtime, permanently adds the string to the executable (even if it were possible to add one while another executable is running, which is usually not possible because the file image is locked). What you probably want to do is simply send a string to another app and have that app display it. You can do this using the WM_COPYDATA message, which you can then add a WM_COPYDATA handler to your application.
-
Is there anyway at runtime to add a string into the string table? What I am trying to do is have a thread load a string to the string table, then use postmessage back to the main thread. Inside of the main thread message handler I want to pop up a warning dialog that will display the string I added to the string table. Is this viable, if not what other approaches could I use?
What Eric suggested is the best way, but if the two threads are within the same process, all you need is a user-defined message and to use either the WPARAM or LPARAM to send a pointer to the string. Here's how you do it with a user-defined message the last parameter is LPARAM and is not used in this example) - I also assume you're using a CString, hence the double-cast for the WPARAM: void CMyClass::SendMyMsg(CString sMsg) { SendMessage(UWM_MYMESSAGE,(WPARAM)((LPCSTR)sMsg), 0); } In your message handler, you'd do this: LRESULT CMyDialog::OnMyMsg(WPARAM wParam, LPARAM lParam) { CString sMyRcvdMsg = (LPCTSTR)wParam; // do something with the string now return 1L; } Using WM_COPYDATA is MUCH more flexible however. I'm working on an app right now that uses WM_COPYDATA quite extensively because of the added flexibility. When it's done, I will be posting it here.
-
What Eric suggested is the best way, but if the two threads are within the same process, all you need is a user-defined message and to use either the WPARAM or LPARAM to send a pointer to the string. Here's how you do it with a user-defined message the last parameter is LPARAM and is not used in this example) - I also assume you're using a CString, hence the double-cast for the WPARAM: void CMyClass::SendMyMsg(CString sMsg) { SendMessage(UWM_MYMESSAGE,(WPARAM)((LPCSTR)sMsg), 0); } In your message handler, you'd do this: LRESULT CMyDialog::OnMyMsg(WPARAM wParam, LPARAM lParam) { CString sMyRcvdMsg = (LPCTSTR)wParam; // do something with the string now return 1L; } Using WM_COPYDATA is MUCH more flexible however. I'm working on an app right now that uses WM_COPYDATA quite extensively because of the added flexibility. When it's done, I will be posting it here.