CInvalidArg exceptions
-
Hi, I am getting a CInvaliArg exception after Doing CWnd::SendMessage The CWnd is a CDialog The Wparam and Lparam are both pointers The ONMESSAGE procedure has WPARAN LPARAM paramters What Causes a CInvalid Arg Exceptions ??
You could try stepping into the SendMessage function to see what causes it to bomb.
The difficult we do right away... ...the impossible takes slightly longer.
-
Hi, I am getting a CInvaliArg exception after Doing CWnd::SendMessage The CWnd is a CDialog The Wparam and Lparam are both pointers The ONMESSAGE procedure has WPARAN LPARAM paramters What Causes a CInvalid Arg Exceptions ??
-
Hi, I am getting a CInvaliArg exception after Doing CWnd::SendMessage The CWnd is a CDialog The Wparam and Lparam are both pointers The ONMESSAGE procedure has WPARAN LPARAM paramters What Causes a CInvalid Arg Exceptions ??
// What Causes a CInvalid Arg Exceptions ?? An invalid dialog's handle, for example :)
They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
Without seeing the exact code no one can guess what you are doing wrong.
One of these days I'm going to think of a really clever signature.
Durning The INITINSTANCE of my CWinApp I allocate via new operator a Derived CEvent class This CLass has 1) buffer allocated via new in the contructor of a command that I use via named pipes "WriteFIle" to get excuted in another process 2) a pointer to a CWND * type object for which I do ::SendMessage( of the responce of that command I use SetEvent to trgger the Write file with the contents of what is in the buffer In My case the CWnd * is a CDialog * but that shouldn't be a problem The corruption ??? if I allocate via new in the ::INITINSTANCE of My Main Thread that object (derived CEvent) it should remain there for the lifetime of the prrocess I save the pointer to that object In My main thread reterive that pointer via AfxGetApp
-
Durning The INITINSTANCE of my CWinApp I allocate via new operator a Derived CEvent class This CLass has 1) buffer allocated via new in the contructor of a command that I use via named pipes "WriteFIle" to get excuted in another process 2) a pointer to a CWND * type object for which I do ::SendMessage( of the responce of that command I use SetEvent to trgger the Write file with the contents of what is in the buffer In My case the CWnd * is a CDialog * but that shouldn't be a problem The corruption ??? if I allocate via new in the ::INITINSTANCE of My Main Thread that object (derived CEvent) it should remain there for the lifetime of the prrocess I save the pointer to that object In My main thread reterive that pointer via AfxGetApp
Very interesting but you need to show the exact code that causes the problem, including the code that creates any objects used in the line causing the problem. Explaining in broad terms as above does not really help.
One of these days I'm going to think of a really clever signature.
-
Very interesting but you need to show the exact code that causes the problem, including the code that creates any objects used in the line causing the problem. Explaining in broad terms as above does not really help.
One of these days I'm going to think of a really clever signature.
In My CWinApp:: InitInstance() I create a Derived CEventObject mybaseeventptr = new MyBaseEvent(FALSE,FALSE,NULL,NULL); which has the following layout
class MyBaseEvent : public CEvent
{
public:
MyBaseEvent(); // contructer
// CSingleLock mylock;
MyBaseEvent(BOOL own, BOOL reset, LPCTSTR mystring, LPSECURITY_ATTRIBUTES mysec);
char *buffer_ptr;
int len;
CWnd *send_window;};
then further down in my CWInApp::InitInstance I create a worker thread which does WriteFile and ReadFile (named pipes IPC) this is triggered via SetEvent from my derived MyBaseEvent Object In Addition to triggering the event I set the CWnd * pointer of the Window were I would like the message sent to
LRESULT CprogDebug::receive_tcpip(WPARAM mywparam,LPARAM mylparam)// CprogDebug message handlers
{
UNREFERENCED_PARAMETER(mywparam);char \*hold\_ptr; CHERC\_CMDApp \*main\_app; MyBaseEvent\* myeventptr;
.
.
.
.myeventptr->send\_window = this; myeventptr->SetEvent(); // SHOW THE WINDOW return TRUE;
}
The following is the worker thread I started which has the SendMessage causing the exception
UINT hercgui_commands(LPVOID lparam)
{
int i;
CString storstrg;
BOOL bresult;
UNREFERENCED_PARAMETER(lparam);
void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
CMutex mymutex(FALSE,"HercLock",NULL);
CSingleLock HercLock(&mymutex);
DWORD dwbytestoread;
CHERC_CMDApp* main_app;
CMainFrame *main_window;
dwbytestoread = 1500;
MyBaseEvent *my_event;main_app = (CHERC_CMDApp *)AfxGetApp();
my_event = main_app->mybaseeventptr;
SetThreadName(GetCurrentThreadId(),"HercGUI");
// CSingleLock *HercLock = static_cast(lparam)->HercLock;
while(1) {
WaitForSingleObject(my_event->m_hObject, INFINITE);
if (!HercLock.IsLocked())
{
HercLock.Lock(INFINITE);WriteFile(main\_app->filehdl, (LPCVOID)my\_event->buffer\_ptr, 30, NULL, (LPOVERLAPPED) &main\_app->herc\_over);
}
bresult = ReadFile(main_app->filehdl,
(LPVOID) my_event->buffer_ptr,
dwbytestoread,
NULL,
(LPOVERLAPPED) &main_app->herc_over1);// WaitFo
-
In My CWinApp:: InitInstance() I create a Derived CEventObject mybaseeventptr = new MyBaseEvent(FALSE,FALSE,NULL,NULL); which has the following layout
class MyBaseEvent : public CEvent
{
public:
MyBaseEvent(); // contructer
// CSingleLock mylock;
MyBaseEvent(BOOL own, BOOL reset, LPCTSTR mystring, LPSECURITY_ATTRIBUTES mysec);
char *buffer_ptr;
int len;
CWnd *send_window;};
then further down in my CWInApp::InitInstance I create a worker thread which does WriteFile and ReadFile (named pipes IPC) this is triggered via SetEvent from my derived MyBaseEvent Object In Addition to triggering the event I set the CWnd * pointer of the Window were I would like the message sent to
LRESULT CprogDebug::receive_tcpip(WPARAM mywparam,LPARAM mylparam)// CprogDebug message handlers
{
UNREFERENCED_PARAMETER(mywparam);char \*hold\_ptr; CHERC\_CMDApp \*main\_app; MyBaseEvent\* myeventptr;
.
.
.
.myeventptr->send\_window = this; myeventptr->SetEvent(); // SHOW THE WINDOW return TRUE;
}
The following is the worker thread I started which has the SendMessage causing the exception
UINT hercgui_commands(LPVOID lparam)
{
int i;
CString storstrg;
BOOL bresult;
UNREFERENCED_PARAMETER(lparam);
void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
CMutex mymutex(FALSE,"HercLock",NULL);
CSingleLock HercLock(&mymutex);
DWORD dwbytestoread;
CHERC_CMDApp* main_app;
CMainFrame *main_window;
dwbytestoread = 1500;
MyBaseEvent *my_event;main_app = (CHERC_CMDApp *)AfxGetApp();
my_event = main_app->mybaseeventptr;
SetThreadName(GetCurrentThreadId(),"HercGUI");
// CSingleLock *HercLock = static_cast(lparam)->HercLock;
while(1) {
WaitForSingleObject(my_event->m_hObject, INFINITE);
if (!HercLock.IsLocked())
{
HercLock.Lock(INFINITE);WriteFile(main\_app->filehdl, (LPCVOID)my\_event->buffer\_ptr, 30, NULL, (LPOVERLAPPED) &main\_app->herc\_over);
}
bresult = ReadFile(main_app->filehdl,
(LPVOID) my_event->buffer_ptr,
dwbytestoread,
NULL,
(LPOVERLAPPED) &main_app->herc_over1);// WaitFo
ForNow wrote:
Maybe the problem is passing pointer objects across threads ?
I think that is true, the
SendMessage()
function actually calls in to the window procedure of the main thread which is illegal. You should use thePostMessage()
function which sends the message into the main thread's message queue.One of these days I'm going to think of a really clever signature.
-
ForNow wrote:
Maybe the problem is passing pointer objects across threads ?
I think that is true, the
SendMessage()
function actually calls in to the window procedure of the main thread which is illegal. You should use thePostMessage()
function which sends the message into the main thread's message queue.One of these days I'm going to think of a really clever signature.
-
Using Worker Threads[^] From the following article seems like I can only Post/SendMessage from a Worker thread only to the MainWindow CMainFrame not to a CDialog
Not true, I use PostMessage() to a CDialog based window all the time. Note that SendMessage() cannot be used to send messages to controls that were *not* created by the thread sending the message. See my answer to This Question[^]