I tried the method as advised. However, an error occurred at the delete(ThreadHD) line. I think that if the thread has exited, there should not be a need to delete it. Please advise. Thanks. CWinThread* ThreadHD = AfxBeginThread(DecodeThreadProc,pfilename,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL); ThreadHD->m_bAutoDelete = TRUE; ThreadHD->ResumeThread(); . . . delete(ThreadHD); ThreadHead=NULL;
searcher08
Posts
-
Assertion error upon second run of thread -
Assertion error upon second run of threadI did not do anything to the object. From the MSDN, I understand there is no requirement to end the thread as long as it is completed normally. I will heed your advise and proceed with the delete of the CWinThread Object. Is this what it is suppose to look like? CWinThread* ThreadHD = AfxBeginThread(DecodeThreadProc,pfilename,THREAD_PRIORITY_NORMAL,0,0,NULL); delete(ThreadHD); ThreadHD=NULL; Many thanks for your advise. Greatly appreciated!
-
Assertion error upon second run of threadThanks. The pFileName was not amended by any function after the AfxBeginThread was called. Can I amend it in the Thread program. I also noticed from the Memory usage monitor that the some memory was not released after the thread ended. I checked the code for errors in freeing pointers and there was no issue. Is there any way of releasing any memory used by the thread? The thread was running fine for the first time. The problem only arises when it was loaded the second time.
-
Assertion error upon second run of threadI started a thread to perform some decoding function. This is to circumvent the problem of the windows not being able to be updated while the decoding is in progress. The code runs perfect for the first run i.e. it went through the file selection process to the completion of the decoding process. However, when I want to decode a second file, an assetion failure occurred during or start of the decoding process. I narrowed down the bug to the 'decode' function in the thread function. Everything runs well second or third time with it commented. Now I know that it is this function causing the problem. This piece of function was running fine when separately called and I went through it many times. Appreciate if you could give advise on this issue. Any comment will be good. Snippets of my code: completed=false; AfxBeginThread(DecodeThreadProc,pfilename,THREAD_PRIORITY_NORMAL,0,0,NULL); while(!completed) { // Perform the windows update. } UINT DecodeThreadProc(LPVOID Paramfilename) { decode((char *)Paramfilename); completed=true; return 0; } searcher08
-
Dialog 'hang' after C procedure called.I would like to use your method instead of creating another thread. However, the computation procedures are in C and not in C++. I am afraid that the above function may not work in the C code as they are all in MFC. I am calling an extern C procedure from a C++ GUI code. Thanks. searcher08
-
Dialog 'hang' after C procedure called.I have not done multi-threading before but looking at the reference books and online tutorial, they are all related to classes or objects. I am only calling a C procedure with a parameter in it. The function needs to be in this form. Do I have to convert my C-procedure to this format? Mine is of the format void decode(char *). UINT MyThreadProc( LPVOID pParam ) // taken from MSDN { CMyObject* pObject = (CMyObject*)pParam; if (pObject == NULL || !pObject->IsKindOf(RUNTIME_CLASS(CMyObject))) return 1; // if pObject is not valid // do something with 'pObject' return 0; // thread completed successfully } Next will be to begin the thread: pNewObject = new CMyObject; AfxBeginThread(MyThreadProc, pNewObject); Where do I put my C-procedure in the above code? How do I know that the thread has ended? Thank you. searcher08
-
Dialog 'hang' after C procedure called.I have completed this dialog window reading in filenames and a progress bar to indicate progress. A timer is used to update the progress bar. However, when I called a C procedure that is computationally intensive, all the edit boxes and menu went blank. The worst thing was that the progress bar was not incrementing. Do take note that the program is running fine except for these side effects. The processed output was tested to be correct. Before I include the C procedure, testing was done to make sure the dialog windows work well with the progress bar etc. Please advise if the computationally intensive C procedure resulted in this issue. If yes, how do I overcome it. searcher08
-
Methods in linking C source code with C++ codeThanks. I have included all the C style code files into the project and segregated the C code out from the C++ code. It has compiled successfully. As usual, after one obstacle is overcome, another one appears. Now I have a problem that is related to Winsock2.h. The below if-define statements were in the program. #ifdef WIN32 #include #else #include #endif It compiled successfully but during build, two errors occurred. rtp.obj : error LNK2001: unresolved external symbol __imp__ntohl@4 rtp.obj : error LNK2001: unresolved external symbol __imp__ntohs@4 The problem has to do with ntohl and ntohs that are defined in Winsock2.h. I have no idea what these two errors are. The program should not have a problem as a build was done in a separate project and it was successful. Please advise. Thanks. searcher08
-
Methods in linking C source code with C++ codeI have developed the GUI using Visual C++ and need to incorporate the functions into the application. The functions are written in C code. I have been trying to link the two codes together but things are not working fine. Approach I took: 1. Inserted the C source code project into my GUI application workspace. 2. Make the GUI application dependent on the C source code project. 3. Included the header files from the C source code project and the compilation was fine. 4. Transfer the functions in main program of the C source code to the GUI Dialog class. No problem in terms of compiling though I am not too sure whether this is correct. Use the following method for the declarations for the C functions in the header file. afx_msg void decode(void); afx_msg void Configure(void); For the function in the cpp file, I used the following method for the first function to be called. The remaining functions remain as C types function headers. If I remove the C++ function declaration, there will be errors as the rest of the C functions could not be recognized. void Dialogc::decode(void); void Configure(void); 5. No problem on compiling. However, during the linking up, there are some extern variables in the image processing files that need referencing to. They are declared in the Dialog cpp file. That is the reason for the "unresolved external symbol _img" and the strings of other error message. I have tried including the Dialogc.h in the source file of the image processing file and they could not recognize the class terms i.e. more error occurred. Thanks. lost in time
-
Errors encountered when linking Dialog based application with C codeI can't use C++ coz the c code was developed by another person and I have to add in the GUI and perform improvement on the code. To recode that will take too long. I have already spent hours on this problem and I am not getting anywhere. I think the answer is out there except that it is not made known. Thanks. searcher08
-
Errors encountered when linking Dialog based application with C codeYou are right. I am a student but an old one. This is the first time linking C code with C++ code. Normally, I used only C++ and it is simply using the defined classes. I have this GUI that was developed and this C-code that performs image processing. I have copied the main() code to the GUI and declared the global variables in the dialog class. The image processing files are brought into the workspace and the GUI made dependent on these files. No problem on compiling. However, during the linking up, there are some extern variables in the image processing files that need referencing to. They are declared in the Dialog cpp file. That is the reason for the "unresolved external symbol _img" and the strings of other error message. I have included the Dialog.h in the source file of the image processing file and they could not recognize the class terms i.e. more error occurred. 2nd question is the declaration of C- code in a C++ program. Can I use this method? The two functions are C functions. afx_msg void decode(void); afx_msg void Configure(void); Thanks a lot for your time and advise. Greatly appreciated. searcher08
-
Errors encountered when linking Dialog based application with C codeI have developed a simple dialog based GUI and was attempting to link some C-code to it in the CDialog class i.e. copying the C code into the file and updating the header files. However, when I started to compile it, the following errors were encountered. I have not done anything with the MFC header files and know that it cannot be due to the program. It might be the way I inserted the c code into the GUI application. Please advise. Thanks. c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type c:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2059: syntax error : 'newline' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2059: syntax error : 'newline' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2238: unexpected token(s) preceding ';' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2059: syntax error : 'newline' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2238: unexpected token(s) preceding ';' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2059: syntax error : 'newline' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2238: unexpected token(s) preceding ';' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2059: syntax error : 'newline' c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(122) : error C2059: syntax error : 'string' c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2091: function returns function c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters c:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2333: 'new' : error in function decla