Click here to Skip to main content
15,904,346 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Provide me all the Possible alternatives to access a member variable and member function from a global function. Pin
Jochen Arndt27-Jul-12 22:47
professionalJochen Arndt27-Jul-12 22:47 
GeneralRe: Provide me all the Possible alternatives to access a member variable and member function from a global function. Pin
Maximilien27-Jul-12 23:41
Maximilien27-Jul-12 23:41 
QuestionCInvalidArg exceptions Pin
ForNow26-Jul-12 17:36
ForNow26-Jul-12 17:36 
AnswerRe: CInvalidArg exceptions Pin
Richard Andrew x6426-Jul-12 18:23
professionalRichard Andrew x6426-Jul-12 18:23 
AnswerRe: CInvalidArg exceptions Pin
Richard MacCutchan26-Jul-12 23:00
mveRichard MacCutchan26-Jul-12 23:00 
GeneralRe: CInvalidArg exceptions Pin
ForNow27-Jul-12 11:13
ForNow27-Jul-12 11:13 
GeneralRe: CInvalidArg exceptions Pin
Richard MacCutchan27-Jul-12 21:25
mveRichard MacCutchan27-Jul-12 21:25 
GeneralRe: CInvalidArg exceptions Pin
ForNow29-Jul-12 10:39
ForNow29-Jul-12 10:39 
In My CWinApp:: InitInstance() I create a Derived CEventObject

mybaseeventptr = new MyBaseEvent(FALSE,FALSE,NULL,NULL); which has the following layout

C++
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

C++
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
C++
   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<Mythread *>(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);

//  WaitForSingleObject(herc_over1.hEvent,INFINITE);
 WaitForSingleObject(main_app->herc_over1.hEvent,INFINITE);


     HercLock.Unlock();
// strncpy(&stor_buffer[0],&buffer[0],100);

        my_event->send_window->SendMessage(WM_HERCGUI_MESS,(WPARAM) my_event->len,(LPARAM) my_event->buffer_ptr);    // statement casing the exception

     i = 1;
         }
   return 0;
 }


Maybe the problem is passing pointer objects across threads ?? as maybe I should just

pass the handle of the CWnd *

Thsnks
GeneralRe: CInvalidArg exceptions Pin
Richard MacCutchan29-Jul-12 10:48
mveRichard MacCutchan29-Jul-12 10:48 
GeneralRe: CInvalidArg exceptions Pin
ForNow29-Jul-12 14:01
ForNow29-Jul-12 14:01 
AnswerRe: CInvalidArg exceptions Pin
Chuck O'Toole30-Jul-12 2:02
Chuck O'Toole30-Jul-12 2:02 
AnswerRe: CInvalidArg exceptions Pin
Eugen Podsypalnikov27-Jul-12 0:37
Eugen Podsypalnikov27-Jul-12 0:37 
QuestionMovies to Galaxy Tab 2-Play movies on Galaxy Tab 2 at Galaxy Tab 2 Column Pin
Member 931218426-Jul-12 15:11
Member 931218426-Jul-12 15:11 
GeneralIs it possible to modify the dialog style at run time? Pin
Falconapollo26-Jul-12 5:12
Falconapollo26-Jul-12 5:12 
GeneralRe: Is it possible to modify the dialog style at run time? Pin
Chris Meech26-Jul-12 6:08
Chris Meech26-Jul-12 6:08 
QuestionLinker Error :C1900 Pin
pix_programmer25-Jul-12 18:59
pix_programmer25-Jul-12 18:59 
AnswerRe: Linker Error :C1900 Pin
Malli_S25-Jul-12 20:25
Malli_S25-Jul-12 20:25 
GeneralRe: Linker Error :C1900 Pin
pix_programmer26-Jul-12 19:59
pix_programmer26-Jul-12 19:59 
GeneralRe: Linker Error :C1900 Pin
Malli_S26-Jul-12 20:15
Malli_S26-Jul-12 20:15 
GeneralCompiler job Pin
_Flaviu25-Jul-12 9:26
_Flaviu25-Jul-12 9:26 
GeneralRe: Compiler job Pin
Maximilien25-Jul-12 9:47
Maximilien25-Jul-12 9:47 
GeneralRe: Compiler job Pin
_Flaviu26-Jul-12 6:22
_Flaviu26-Jul-12 6:22 
QuestionRe: Compiler job Pin
CPallini25-Jul-12 22:16
mveCPallini25-Jul-12 22:16 
GeneralRe: Compiler job Pin
Malli_S25-Jul-12 23:10
Malli_S25-Jul-12 23:10 
AnswerRe: Compiler job Pin
_Flaviu26-Jul-12 1:21
_Flaviu26-Jul-12 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.