Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CInvalidArg exceptions

CInvalidArg exceptions

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    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 ??

    Richard Andrew x64R L E 3 Replies Last reply
    0
    • F ForNow

      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 ??

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F ForNow

        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 ??

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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.

        F 1 Reply Last reply
        0
        • F ForNow

          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 ??

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          // 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. :)

          1 Reply Last reply
          0
          • L Lost User

            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.

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • F ForNow

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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.

              F 1 Reply Last reply
              0
              • L Lost User

                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.

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                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

                L 1 Reply Last reply
                0
                • F ForNow

                  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

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  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 the PostMessage() 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.

                  F 1 Reply Last reply
                  0
                  • L Lost User

                    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 the PostMessage() 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.

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    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

                    C 1 Reply Last reply
                    0
                    • F ForNow

                      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

                      C Offline
                      C Offline
                      Chuck OToole
                      wrote on last edited by
                      #10

                      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[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups