|
I want to send a message to WindowProc() function of application from a static callback function.
The PostMessage() and SendMessage() functions makes "Unhandled Exception". Can anybody tell me how to make the PostMessage() call no error.
Best Regards,
Suman
-- modified at 2:39 Monday 23rd July, 2007
|
|
|
|
|
Try changing your code to look something like this:
BOOL CMyDlg::OnInitDialog()<br />
{<br />
CBaseClass::OnInitDialog();<br />
PostMessage(MY_MESSAGE,0,0);<br />
return TRUE;<br />
}
Note I have used Postmessage() rather than SendMessage()
-Randor (David Delaune)
|
|
|
|
|
Hi,
Thanks for your help.
The exception is happening if I call PostMessage() or SendMessage() from inside a static function(callback). If I call from somewhere else it is ok.
Best Regards,
Suman
|
|
|
|
|
Is the function a static 'member' function?
if not...
Have you tried the global namespace Postmessage?
::PostMessage(hwnd,msg,0,0);
Can you paste the error message here?
|
|
|
|
|
Hi,
If I use global namespace Postmessage, there is no error.
The runtime error message is as follows:
"Unhandled exception at 0x7c28e12a (mfc71d.dll) in MIDIApplication.exe: 0xC0000005: Access violation reading location 0x00000020."
The code causing the error is:
AfxGetMainWnd()->SendMessage(wMsg, 0, dwParam1); where wMsg is the message and dwParam1 is the LParam in argument list of static callback function: MidiInProc() .
Thanks for your help!!
Best Regards,
Suman
|
|
|
|
|
What is the result of the following (put before your code):
CWnd *pWnd = AfxGetMainWnd();
__asm int 3
When you run this code a breakpoint will be generated at the __asm int 3 line. Inspect the variable pWnd at this point. Is is NULL? If not what is its value?
Steve
|
|
|
|
|
Hi, pWnd is not NULL. The value is 0x0012ea24.
Is it possible to use DispatchMessage() to send message to WindowProc() .
What is difference between DispatchMessage and PostMessage() ?
Best Regards,
Suman
-- modified at 4:37 Monday 23rd July, 2007
|
|
|
|
|
DispatchMessage is used while implementing Message loop along with GetMessage. If you want to post a message into the message loop you need to use either PostMessage or SendMessage
"a child will grow up to become an adult, but you can never stop the adult from acting like a child"
|
|
|
|
|
Hello again,
I am happy that your issue has been resolved. But, so you can learn from this experience with others... let me explain my theory about what was happening.
You stated that you were calling AfxGetMainWnd() from within a callback function. Callbacks are often not excuting within the same thread as the main window. They may be called from an external thread.
From the MSDN: http://msdn2.microsoft.com/en-us/library/waas15s1(VS.80).aspx[^]
"If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call."
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
Thank you very much for your great help!!
So, we should be careful when implementing callback!!
Thanks & Regards,
Suman
|
|
|
|
|
What kind of exception? From where is it being thrown? What does the code look like around the "throw" site? What are the parameters you're passing to the API? Is the HWND valid? In short we need some more detailed information.
Steve
|
|
|
|
|
Hi,
I can now send message using global namespace SendMessage().
Please see my reply to Mr. Randor above for the error details.
If you need other info please ask me.
Best Regards,
Suman
|
|
|
|
|
Can any one tell me what could be problem with following code ?
::CoInitialize(NULL);
m_rsocp.CreateInstance(__uuidof(Recordset));
m_rsocp->Open((LPCTSTR)str,(LPCTSTR)m_strConnection,adOpenDynamic,adLockOptimistic,adCmdUnknown);
if(FAILED(m_rsocp->QueryInterface(__uuidof(IADORecordBinding),(LPVOID*)&binding)))
_com_issue_error(E_NOINTERFACE);
adoctrl.m_UserId = tempuserid;
adoctrl.m_NewAccount = LArray[0];
adoctrl.m_InactivateAccount = LArray[1];
binding->AddNew(&adoctrl);
binding->Update(&adoctrl);
binding->BindToRecordset(&adoctrl);
m_rsocp->Close();
::CoUninitialize();
|| ART OF LIVING ||
|
|
|
|
|
1.) Is GetSystemDefaultLangID() the best way to detect which language version of the OS is running? Or GetUserDefaultLangID() ? Or something else?
2.) Is there a way to temporarily trick the US version of XP into thinking it's in another language? I tried changing the "Default input language" in the "Regional and Language Options" control panel, along with both GetSystemDefaultLangID() and GetUserDefaultLangID() in my code, but they both return English regardless of what I set for the default input language. Do I need localized installs of XP to test my localizations?
|
|
|
|
|
Do I need localized installs of XP to test my localizations?
No.
Instead you can change the language in
"Regional and Language Options" -> "Advanced" tab.
|
|
|
|
|
That change did not seem to affect anything. After reboot, XP was still in English and my code (calling GetSystemDefaultLangID() ) is still reporting English. I set the option to both Vietnamese and Chinese(Taiwan), but neither had any effect.
|
|
|
|
|
For an AutoCAD application I need to temporarily hide a dialog window and return control to the main window, in order to enable the user to select objects on the drawing screen. After the user has selected objects, control is returned to the dialog.
I do not use MFC, because I subclassed an existing dialog procedure.
What sequence of messages should I send in order to make the dialog hidden and visible again?
|
|
|
|
|
Hi,
I would like to know how to add a resource to an external exe file. For instance you have a.exe which is your main program and you want to add the file example.txt as a resource to the file b.exe.
I don't know if that's possible but if it is and if someone have the solution of that problem I would really appreciate to know it...
Thanks
Manthis
|
|
|
|
|
With code or manually? If you mean manually, open the EXE in a resource editor like VS, and add the file with the editor. With code, use the resorce APIs, BeginUpdateResource() , UpdateResource() , EndUpdateResource()
|
|
|
|
|
Manthis wrote: I don't know if that's possible but if it is and if someone have the solution of that problem I would really appreciate to know it...
Read it http://www.codeproject.com/cpp/UpdateResource.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
One way is to include all the contents of file as one long string in the string table resource of external exe.
For this uses the following functions:
LoadLibrary() for destination/external exe
FindResource() for finding the string table.
Load resource()
Lockresource()
BeginUpdateResource()
UpdateResource()
EndUpdateResource()
File contents->Long String ->Any one String Table Entry ->String tableResource -> External Exe.
|
|
|
|
|
All right thanks guys for these quick answers, I really appreciate it...
|
|
|
|
|
Hello,
I have a question for you. I have a program is based on a basic binary tree.
There needs to be a function to swap nodes or from left to right. so in other words,
if 1 is the root and on the left is a 2 and on the right is a 3, I would want to swap the 2 and 3.
For each node entered.
Any ideas on how to write this out?
Thanks.
Tiffani
|
|
|
|
|
first you will have to walk the tree.
next you will need to construct a new tree, the new tree will simply need to change how it's comparing the elements!
think about it..have fun on the homework, no cheating
Yours Truly, The One and Only!
|
|
|
|
|
Hello,
I have a question for you. I have a program is based on a basic binary tree.
There needs to be a function to swap nodes or from left to right. so in other words,
if 1 is the root and on the left is a 2 and on the right is a 3, I would want to swap the 2 and 3.
For each node entered.
Any ideas on how to write this out?
Thanks.
Tiffani
Diablaaz@aol.com
-- modified at 18:14 Sunday 22nd July, 2007
|
|
|
|