|
msdn says _beginthreadex calls CreateThread internally. So, i think the return value should be similar with what returned by CreateThread. As msdn says, we can resume a thread created by CreateThread with CREATE_SUSPENDED flag. So, i use resume a thread created with CREATE_SUSPENDED flag, the the program will crash at ResumeThread call. but there is nothing related about how to resume a thread created by _beginthreadex.
So, how to resume a thread created by _beginthreadex?
|
|
|
|
|
I'm not sure I got you. Did you try to call beginthreadex with CREATE_SUSPENDED flag and then ResumeThread failed (making the application crash)?
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]
|
|
|
|
|
yes. so did the program crash at ResumeThread
|
|
|
|
|
Here's code from an old thread wrapper class of mine.
It never "crashed" for me.
bool CMyOldWorkerThread::Run(int priority, DWORD dwThreadCreateFlags)
{
hThread = (HANDLE)_beginthreadex(NULL, 0, WorkerThreadProc, (LPVOID)this,
CREATE_SUSPENDED | (unsigned)dwThreadCreateFlags, (unsigned *)&dwThreadId);
if (hThread)
{
::SetThreadPriority(hThread, priority);
if (0 == (dwThreadCreateFlags & CREATE_SUSPENDED))
{
::ResumeThread(hThread);
}
return true;
}
return false;
}
What are you doing differently?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks. it works well now. The crash dues to my carelessness, the reason was not the ResumeThread call.
|
|
|
|
|
Hello everyone,
Could anyone show me a sample about how to use these two commands in Windbg please? I read the document in debugger.chm, but confused. I did search in Google and MSDN, but not find an easy to learn sample.
thanks in advance,
George
|
|
|
|
|
Hi everybody,
i have a problem with the sizing of the rows of a splitter.
I coded a little sample with a main_splitter with 4 rows.
This is how it looks at startup.
http://filehosting.at/images/download.php?file=4dbf41d6c1a6e28de6a24e27e60ae9ee
[^]
Then the user could change the height of the rows, like this for example:
http://filehosting.at/images/download.php?file=d3f0203679e34d9bb3159d231e898d89[^]
But wen the user now maximize the window i want change the height proportional to the size of the window.
An when he change the height of the rows in fulscreen and restoe the windows i will change
the height of the rows proportional again.
here is my code, i try to figure it out fore hours now but it won't work
<code>
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CRect spRect;
CRect cr;
GetClientRect(&cr);
GetClientRect(&spRect);
m_Splitter_Main.CreateStatic(this, 4, 1);
m_Splitter_Main.SetRowInfo(0, spRect.Height()/4, 0);
m_Splitter_Main.SetRowInfo(1, spRect.Height()/4, 0);
m_Splitter_Main.SetRowInfo(2, spRect.Height()/4, 0);
m_Splitter_Main.SetRowInfo(3, spRect.Height()/4, 0);
m_Splitter_Main.CreateView(1, 0, RUNTIME_CLASS(CTest_01View), CSize(0, cr.Height()/4), pContext);
m_Splitter_Main.CreateView(2, 0, RUNTIME_CLASS(CTest_01View), CSize(0, cr.Height()/4), pContext);
m_Splitter_Child_1.CreateStatic(&m_Splitter_Main, 1, 3, WS_CHILD | WS_VISIBLE, m_Splitter_Main.IdFromRowCol(0, 0));
m_Splitter_Child_1.CreateView(0, 0, RUNTIME_CLASS(CTest_01View), CSize(cr.Width()/3, 0), pContext);
m_Splitter_Child_1.CreateView(0, 1, RUNTIME_CLASS(CTest_01View), CSize(cr.Width()/3, 0), pContext);
m_Splitter_Child_1.CreateView(0, 2, RUNTIME_CLASS(CTest_01View), CSize(cr.Width()/3, 0), pContext);
m_Splitter_Child_2.CreateStatic(&m_Splitter_Main, 1, 2, WS_CHILD | WS_VISIBLE, m_Splitter_Main.IdFromRowCol(3, 0));
m_Splitter_Child_2.CreateView(0, 0, RUNTIME_CLASS(CTest_01View), CSize(cr.Width()/2, 0), pContext);
m_Splitter_Child_2.CreateView(0, 1, RUNTIME_CLASS(CTest_01View), CSize(cr.Width()/2, 0), pContext);
return TRUE;
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
int iCur_cy, iMin_cy;
iMin_cy = 0;
CRect spRect;
m_Splitter_Main.GetClientRect(spRect);
if ((nType == SIZE_MAXIMIZED)||(m_Splitter_Main.IsWindowVisible() && nType == SIZE_RESTORED))
{
m_Splitter_Main.GetRowInfo(0 ,iCur_cy, iMin_cy);
m_Splitter_Main.SetRowInfo(0, iCur_cy, 0);
m_Splitter_Main.RecalcLayout();
}
}
</code>
I hope i could discribe the problem good enough !
Many thanks & best regards
Croc
|
|
|
|
|
Hello everyone,
I posted the source codes related with assembly code for a very simple program below. I have inlined my questions.
Let me repeat my question here,
1. ebp is not used in function main? only esp is used to represent variables on stack?
2. what is the purpose of rdx in statement "lea rdx,[rsp+30h]", store the 2nd parameter to operator <<, which is address of b (address of an integer)?
#include <iostream>
using namespace std;
int foo (int a)
{
int b;
cin >> b;
a = a * b;
return a;
}
int main()
{
0000000140001000 sub rsp,28h
cout << foo (10);
0000000140001004 mov rcx,qword ptr [__imp_std::cin (140002080h)]
000000014000100B lea rdx,[rsp+30h]
0000000140001010 call qword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (140002078h)]
0000000140001016 mov r11d,dword ptr [rsp+30h]
000000014000101B mov rcx,qword ptr [__imp_std::cout (140002090h)]
0000000140001022 lea edx,[r11+r11*4]
0000000140001026 add edx,edx
0000000140001028 call qword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (140002088h)]
return 0;
000000014000102E xor eax,eax
}
regards,
George
|
|
|
|
|
rdx is the address of b.
It is optimized.
foo became inline, and ebp is also optimized away.
logics
|
|
|
|
|
Thanks followait,
So, ebp is always used or not? Previously I think ebp is always used even if in optimized code.
regards,
George
|
|
|
|
|
ebp is not a must.
Without ebp, all parameters and local variables can be addressed,
and when the function returns the stack can be balanced as well.
With ebp it's more clear but slower.
logics
|
|
|
|
|
Thanks followait,
Good to learn from you ebp is not a must to be used.
regards,
George
|
|
|
|
|
eg.
HRGN
Here is the code in MFC, does it make sense?
this can't be NULL when the non-static member function is called, can it?
_AFXWIN_INLINE HGDIOBJ CGdiObject::GetSafeHandle() const
{ return this == NULL ? NULL : m_hObject; }
logics
|
|
|
|
|
followait wrote: this can't be NULL when the non-static member function is called, can it?
Certainly it can:
Object *ptr = NULL;
ptr->Method(); Remember, the this pointer is simply an implicit argument to a non-static member function. It's as if this:
class Object {
void Function(int arg1, int arg2);
};
void Object::Function(int arg1,int arg2)
{
} was implemented as
void Object_Function(Object *this,int arg1,int arg2)
{
};
|
|
|
|
|
There's no dereferencing involved when calling a non-virtual method. All that happens is the pointer value is passed to the method, and becomes the value of this .
|
|
|
|
|
Hi,
I have Dos Console process which has a lot of data which I want to
Display in WIN32 GUI
So I did a CreateProcess to create the WIN32 app exported the structure unfortunatlly the data in the DLL exported structure seems to be lost
Hmm. seems that even though the address of DLL is the same in both the Dos Console and the WIN32 app
The data must be shared.....
from research is seems that along with exporting this structure
I have to put it in the shared data segment
a #pragma data_seg(".SHARED") and #pragma data_seg() must be wrapped around structure in additon to telling the linker via #pragma
that this is Read / Write section via
#pragma comment(linker, "/section:.SHARED,RWS)
One caveat to all this is that the variables must be initialized
There a lot of memebers in this structure to initialize
but alas if there is no other way
I been reading about Mapped Memory files
all suggestion are welcome
thankx
|
|
|
|
|
hello everybody!
now I want to draw something on the flash control background
I have already realized the ole container of flash control,
in the WM_PAINT message handle function,
I call OleDraw to Draw the content of Flash at first
after that, I Draw sth on the HDC,
But I found that some event of flash will redraw itself,
so, the content that I draw is always covered by the content of flash control
I want to draw sth. on the flash control background
reference url: http://www.codeproject.com/KB/COM/flashcontrol.aspx
I found that the IAdviseSink interface
hr = m_lpO->QueryInterface(IID_IViewObjectEx, (void **)&m_lpViewObjectEx);
after that,
if(S_OK == pview->SetAdvise(DVASPECT_CONTENT, 0, (IAdviseSink*)this) )
{
TRACE("S_OK");
}
the debug window display "S_OK"
the "this" pointer is
class COleContainerWnd : virtual public IOleClientSite,
virtual public IOleInPlaceSiteWindowless,
virtual public IOleInPlaceFrame,
virtual public IStorage,
virtual public IAdviseSink
but can't catch IAdviseSink::OnDataChange() and IAdviseSink::OnViewChange() Event
why? -_-!!!!!!
Now the question is
How to catch the redraw event of Flash control,
and add some extra code in the redraw handle function of flash control
Sincerely
|
|
|
|
|
I have an application which has a Dialog and a Tab control, each tab is a PropertyPage.
I don't have a Oninit handler for my Propertypages.
The situation I ran into is because I had to create a menu in the main dialog.
I have a Edit control and CComboBox in my Property page PPOne.
In my file menu, I do File Open, through which I can open a file and read its contents, am able to populate memory,then I perform the step m_oPPOne.Create(IDD_PP_ONE)(this is from a class derived from Ctabctrl) I see the tab appear, now how can I make the the data for the controls on this PP appear in their fields ?.
Example: Normally when I am on the PP if I click a button, this below function works fine.
Void CPPOne::OnBtnRefreshClicked
{
CString str;
str.Format("%d",some_int1);
cs_my_edit_control = str;
UpdateData(TRUE);
ccb_my_combo_box.SelectString(0,*(&my_predef_Str[0+some_int2]));
}
But if I call this above function from my main dialog, it fails on the UpdateData line with a assertion failure in line 4184 of wincore.cpp saying doing UpdateData before DoModal.
How can I overcome this? any suggestion would help.
Best Regards
RV
|
|
|
|
|
What is the difference among the OnClose(),OnDestroy() and the DestroyWindow()?
The other question:When you want to close a window,you can click the button "X" on the upper-right of the window.In the windows messages,what messaget dose his action invoke,WM_CLOSE,WM_DESTROY or other messages?
|
|
|
|
|
Have you considered using the debugger to put a breakpoint in each of those message handlers to see what happens?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Yes, I have done it.When I put a breakpoint in the OnClose() and OnDestroy(),I close the windows,both is equvalent.
Do you have the more wonderful method?
|
|
|
|
|
WM_DESTROY is sent as a result of calling DestroyWindow.
WM_CLOSE is sent to you to close the window. but you may close it or not. it's just a request. you can accept the request by calling the parent class's OnClose().
WM_DESTROY is sent when the window is about to be destroyed even if you don't like to close it. It will be closed anyway and then the class destructor will be called.
|
|
|
|
|
WM_CLOSE is sent when you click the close button (or hit Alt+F4 or close the window some other way). Normally, you would do some cleanup and then call DestroyWindow() . If you let DefWindowProc handle WM_CLOSE , it will call DestroyWindow() for you. WM_DESTROY notifies you that the window is being destroyed.
|
|
|
|
|
Im new in C++. I want to read a text file in my Win32 Console Application of C++.net 2005, how can i do it? Kindly tell me in .net 2005 unmanaged code plz.
nOmI
|
|
|
|
|
Check out CreateFile() and <codereadfile()>. C++ also has stream classes like ifstream .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|