|
Can you tell me please how can call or access a global variable or a function defined in th Doc.cpp or anyaother class from inside UINT ThreadProc (LPVOID param)?
UINT ThreadProc(LPVOID param)
{
CTestDoc* pDoc = GetDocument(); // error: GetDocument() is not defined???
ASSERT_VALID(pDoc);
::WaitForSingleObject(m_Thread_Sel_Start.m_hObject , INFINITE);
::MessageBox((HWND)param, strThread_Start, strThread_Caption, MB_OK);
CSQLCommand::FindSQLCmd(pDoc,m_strSelect);// error :m_strSelect is defined in the CTestView.h but he can not find it , pDoc is already unkown
bool bKeepRunning = true;
while(bKeepRunning)
{
int nResult = ::WaitForSingleObject (m_Thread_Sel_End.m_hObject ,0);
if(nResult == WAIT_OBJECT_0)
bKeepRunning = false;
}
::PostMessage((HWND)param, WM_THREADENDED, 0, 0);
return 0;
}
Can i define the UINT ThreadProc(LPVOID param) in the CTestDoc.cpp?
And why when i declare UINT ThreadProc(LPVOID param) in the CTestView.h i get this error:
error C3867: "CTestView::ThreadProc": use "&CTestView::ThreadProc".
and when i use &CTestView::ThreadProc i get a csting problem that can not be solved through an explict cast.
|
|
|
|
|
Your problem stems mainly from the fact that the ThreadProc function is static, and therefore cannot access any instance members of your application class.
The easiest fix is the following:
When you call AfxBeginThread, pass the "this" pointer as your Param.
Then, inside the ThreadProc, cast the Param back to whatever object it was when you passed it originally, such as your app class or your document class.
That way, you now have access to all the instance members of your class by using the -> operator.
|
|
|
|
|
Hello,
i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code:
void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel)
{
m_Thread_Sel_Start.SetEvent ();
HWND hWnd = GetSafeHwnd();
m_strSelect = strSel;
m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp
// and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp
AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function
}
UINT ThreadProc
(
LPVOID param
)
{
(CTestView*)param-> // casting to CTestView did not work?
return 0;
}
|
|
|
|
|
You're almost there.
The correct cast is:
((CTestView*)param)->function();
|
|
|
|
|
okay but i got an application crash hier:
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CView::AssertValid();
}
#ifndef _WIN32_WCE
void CTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif
#endif
|
|
|
|
|
Do you have a valid CTestView object before starting your thread?
If not, that will cause this crash.
|
|
|
|
|
Hi all,
I am writing contents from an application into a notepad file.. i have used fwrite function... but the file is not saving in unicode format as default...
i want the file to be saved in unicode format...can anyone guide me how to make it through?
Thanks,
Rakesh.
|
|
|
|
|
|
can you please update me the latest version of Dr. Watson, the dump must be suitable to open ind VS 2005 Team edition.
I had older version of Dr. Watson installed, and the dump created with the version is not supported in VS 2005. I get below error msg, Please advice
---------------------------
Microsoft Visual Studio
---------------------------
Unable to start program 'C:\.........\DebugMDd\user8.dmp'.
Debugging older format crashdumps is not supported.
---------------------------
OK
---------------------------
|
|
|
|
|
|
Hi,
i when exactly ExcludeCliprect is usefull.. i had a look in msdn it was as follows but i do not know what is a clipping region..
Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
|
|
|
|
|
kumar sanghvi wrote: but i do not know what is a clipping region..
See here and here.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
i am making my application unicode supporting one. i have to read content from a file..(say a notepad file)..
i have the contents in this format: "rakesh","male"
"shekar","male" etc.,
When i read the content, it is reading as "rakesh","male"(one squarebox)". when i debugged, i found the hexadecimal value of the box as FEFF which is UNICODE_BOM value..(if i am correct)..
So,after some operations(trim operations),it will come as "rakesh","male"" which leads my final output as rakesh" , male;
how to get rid of that square box? why is it coming actually? if i remove that square box, i can overcome this double quote prob. i think...
Please let me know if am unclear in my question..
Thanks,
Rakesh.
|
|
|
|
|
Someone might be able to offer you help if you show your code.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
It sounds like you are make a call to fgetws() or a similar function which doesn't remove the new line character at the end of the string.
|
|
|
|
|
Hello all,
I would like to ask for an example or documentation how to add the VBA editor to my MFC application (like Excel and Word and other apps (not just MS) do).
Thanks a lot for your support
ulretsam
|
|
|
|
|
|
plzzzzzzzzz help me i read 256 bitmap image in the form of array & i display it but while displaying it not shows its actuall colors .It means it shows blue color at the place of red & white color at the place of yellow & so on I set the VGA graphics mode & use putpixel() & setcolor() graphics functions i want to use this functions onli cause it gives other information coractlly so plzzz tell me how can i display it?
|
|
|
|
|
|
hiiiiiiiiii thanx for sending me code but actualy i use the same methode only initialising graphics mode
EGA which supports 16 colors but i want to put 256 colors plz help for this code i want to display image which I read from hard disk right now my sample image is of tiger which gives correct shape & size it puts colors also but with wrong colors like white insted of yellow etc........
|
|
|
|
|
|
no i had allready load the image put it in array form also now i want to show it on output window .See i read the image file using fopen ,fread functioss also read its header & i can display it on the o/p successfully but the color information is wrong it shows wrong shades of color so i can understand now which graphics mode or function shall i use to put proper colors in image only color shades of my image are wrong like background in original image is red & in my o/p image it is blue also tiger color it shows gray & white likewise.
|
|
|
|
|
|
thanx man but i have to use only graphics mode this code is run only on vga i am using graphics .h header & i can show my image properly only the problem is that it not shows colors perfectly i allready mention like it shows blue color in the portion of red color & so on its i use ega mode or vga mode & putpixel()
function to put the proper color pixels i had allready studied this all codes & now my program is working properly only color problem thats all byeeeeeeeeee............
|
|
|
|
|
Hallo i have the following problem:
i need to start and end a thread by using Event Objects in MFC, following is the code in the ThreadView.cpp:
Event m_threadStart;
Event m_threadEnd;
ON_MESSAGE(WM_CREATE, OnCreate) // causes a casting problem
void CThreadView::OnStartThread()
{
m_threadStart.SetEvent ();
}
void CThreadView::OnStopThread()
{
m_threadEnd.SetEvent ();
}
int CThreadView::OnCreate(LPCREATESTRUCT lpCreateStruct) // defined in ThreadView.h liks this: afx_msg OnCreate(LPCREATESTRUCT lpCreateStruct)
{
HWND hWnd = GetSafeHwnd();
AfxBeginThread(ThreadProc, hWnd, THREAD_PRIORITY_NORMAL);
return 0;
}
LONG CThreadView::OnThreadended(WPARAM wParam, LPARAM lParam)
{
CString strThreadEnd = _T("Thread ended.");
AfxMessageBox(strThreadEnd, 0,0);
return 0;
}
UINT ThreadProc(LPVOID param)
{
CString strThread_Start = _T("Thread aktiviert.");
CString strThread_Stop = _T("Thread deaktiviert.");
CString strThread_Caption = _T("Thread");
::WaitForSingleObject(m_threadStart.m_hObject , INFINITE);
::MessageBox((HWND)param, strThread_Start, strThread_Caption, MB_OK);
bool bKeepRunning = true;
while(bKeepRunning)
{
int nResult = ::WaitForSingleObject (m_threadStart.m_hObject ,0);
if(nResult == WAIT_OBJECT_0)
bKeepRunning = false;
}
::PostMessage((HWND)param, WM_THREADENDED, 0, 0);
return 0;
}
First the Compiler bring an error c2440: ON_MESSAGE(WM_CREATE, OnCreate) // causes a casting problem
I can not cast.
Something is terribly wrong with this code , please help.
|
|
|
|