|
The trick is to fill the stack with a pattern before the thread is launched. Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size. But I don't want to do this in a debugger, I want to write code that will compute that. So, I need to create a suspended thread, find it's stack pointer, fill it's memory with a pattern, then start the thread. And my problem is, how do I get the stack pointer of another thread ?
|
|
|
|
|
Zykalus wrote:
Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size.
I see... You might want to have a look at GetThreadContext() then. Haven't used it myself, but it looks like just what you're looking for.
|
|
|
|
|
You might want to look at VirtualQuery.
The region size will be approximately how much memoryhas been commtted for stack size. I am pretty sure it never shrinks. Of course, the value is in the granularity of the syste's smallest allocation unit, which I think is 8K. But anyway, it gives you an idea if it used 64K versus 1 MB or such.
You need to pass the value of ESP register in as the lpAddress to the VirtualQuery call.
Use a little bit of inline assembler to get to it.
|
|
|
|
|
Thanks, I'll look into it. What I want to do is add debugging code in my app,. Currently, all threads are using the default size. But since I have a lot of threads, I just want to add in my thread code that will tell me how much was use during the thread life time.
"Invent a idiot-proof system and a new improved idiot will be invented"
|
|
|
|
|
Windows will expand the stack as needed.
Software Zen: delete this;
|
|
|
|
|
Hi all,
I was trying to trigger a button click event programmatically by doing
m_MyButton.SendMessage(BN_CLICKED);
but the event handler was not getting invoked. What did I do wrong and what's the correct way to do it?
Thank you for the help.
|
|
|
|
|
BN_CLICKED is not a message. It's a notification code to be used in the context of a WM_COMMAND message.
You need to send the WM_COMMAND message to the button's parent window, with the following parameters
wParam: MAKEWPARAM(id, BN_CLICKED)
lParam: m_MyButton.m_hWnd
where id is the numeric identifier of the button.
Example:
void CMyWindow::SomeMethod
{
SendMessage(WM_COMMAND, MAKEWPARAM(IDC_MY_BUTTON, BN_CLICKED), (LPARAM) m_MyButton.m_hWnd);
}
--
jlr
http://jlamas.blogspot.com/[^]
-- modified at 15:49 Wednesday 5th October, 2005
|
|
|
|
|
Ok, understand now.
Thank you very much!
|
|
|
|
|
Thanks Jose Lamas Rios for your solution. It helped me add button click event programmatically
|
|
|
|
|
Only one instance of the program can run at one time. When launching the program from explorer, the code below works just fine. But when I try to launch it from another program, the following occurs:
1)When an instance already exists, it only activates and maximizes the window when the window is in the minimized state. When it's not minimized but hidden behind other windows, it merely activates it (icon blinking in the taskbar) and does not maximize it or bring it to the foreground. Why is that?
2)When no instance exists, it launches the program but the window is not maximized or activated. It gets maximized only during initial startup.
Thanks!
BOOL CMyApp::InitInstance()
{
m_Instance = ::CreateMutex(NULL, FALSE, AfxGetApp()->m_pszExeName);
DWORD dwMutexErr = GetLastError();
if (dwMutexErr == ERROR_ALREADY_EXISTS)
{
CWnd *pPrevWnd = CWnd::GetDesktopWindow()->GetWindow(GW_CHILD);
while (pPrevWnd)
{
if ( ::GetProp(pPrevWnd->GetSafeHwnd(), AfxGetApp()->m_pszExeName) )
{
if ( pPrevWnd->IsIconic() )
pPrevWnd->ShowWindow(SW_RESTORE);
pPrevWnd->SetForegroundWindow();
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
return FALSE;
}
pPrevWnd = pPrevWnd->GetWindow(GW_HWNDNEXT);
}
}
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(MainFrame))
return FALSE;
m_pMainWnd = pMainFrame;
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
return TRUE;
_Module.UpdateRegistryFromResource(IDR_APP, TRUE);
_Module.RegisterServer(TRUE);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
::SetProp(pMainFrame->GetSafeHwnd(), m_pszExeName, (HANDLE)1);
return TRUE;
}
-- modified at 13:11 Wednesday 5th October, 2005
|
|
|
|
|
|
1. Try BringWindowToTop .
2. Replace SW_RESTORE with SW_MAXIMIZE in the pPrevWnd->ShowWindow call.
Regards,
BB
http://spin.bartoszbien.com
|
|
|
|
|
The above proved unsuccessful. What I did try was minimize the window and then restore it if the window was not already minimized. You can see the window minimize and then pop back up for display. Why does minimizing it work? This seems like poor coding to me but it serves as a workaround? How can I make it more efficient? Thanks!
if ( !pPrevWnd->IsIconic() )
{
pPrevWnd->ShowWindow(SW_MINIMIZE);
}
pPrevWnd->ShowWindow(SW_RESTORE);
pPrevWnd->SetForegroundWindow();
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
|
|
|
|
|
Hi fellows
I'm a doubt: I have this program to read each line of a file and write into it again with some new values, but the program doesn't read the lines and in the message box, it show the value "0". Who can helps me to solve this?
I want to read all lines of my file and write values in a determined position.
Below the code, thanks a lot for help:
void EscreveArquivo(char* cValues)
{
notas* tNotas = new notas;
char* cValue = new char[256];
FILE* pFile;
bool bEnd = false;
char* c = new char[256];
pFile = fopen("c:\\arquivo.txt", "a");
if(pFile != NULL)
{
while(!feof(pFile))
{
fread(cValue,4,1,pFile);
tNotas->iNota = atoi(cValue);
MessageBox(0, itoa(tNotas->iNota,cValue,10),"tela",0);
notas* aux = new notas;
aux->next = tNotas;
tNotas = aux;
break;
}
while(!bEnd)
{
//fread(tNotas, sizeof(tNotas), 1, pFile);
//tNotas->iNota += atoi(cValues);
switch(tNotas->iNota)
{
case 1:
i1Real += 1;
break;
}
itoa(i1Real,cValue, 10);
fseek(pFile, 2, 0);
fwrite(cValue, 1, 1, pFile);
if(tNotas->next == NULL)
{
bEnd = true;
}
tNotas = tNotas->next;
}
}
fclose(pFile);
delete tNotas;
delete[] cValue;
}
int main()
{
char* cBuffer = new char[256];
EscreveArquivo(itoa(10,cBuffer,10));
|
|
|
|
|
Alex Cutovoi wrote:
fread(cValue,4,1,pFile);
tNotas->iNota = atoi(cValue);
If you know the first item to read from the file is a number, why not treat it as such?
fread(&tNotas->iNota, sizeof(int), 1, pFile); Alex Cutovoi wrote:
tNotas->iNota = atoi(cValue);
atoi() will not work unless cValue is nul terminated.
What exactly are you trying to do? All of the calls to atoi() and itoa() appear to be making things unnecessarily hard.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
when you compile that code, you should see a warning that looks a lot like this: "warning C4129: 'm' : unrecognized character escape sequence".
\ is the C/C++ escape character, so if you want to put a single '\' inside a literal string, you have to use '\\' .
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
because when you hard coded sValue, the compiler sees '\m' as an escape character...
make this instead :
char sValue[] = "So\\meText";
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 11:24 Wednesday 5th October, 2005
sorry Chris, i have a very very very slow connection today, so excuse my redundant answer... (or CP servers are having trouble ?)
|
|
|
|
|
I need to write a program to send data to com port with 8bit characters.
(0x00 - 0xFF)
But I can only use CString as 7 bits ANSI.
Please tell me how to use CString as 8 bits!
Thank you very much!
|
|
|
|
|
|
Chris Losinger wrote:
you can't.
you uderstood the question ????
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello,
CString uses 8 bits! A byte is 8 bits and CString uses no less... If you want to specify values other than the visible characters, you should call GetBufferSetLength(new length) . This will retrieve a pointer to the internal character buffer. Manipulate it as required (using code>unsigned char's and a lot of casting. Then call ReleaseBuffer() and make sure that there are no null terminators in the buffer, but only one on the end.
This is a dirty hack that you should not use, but use a BYTE buffer or
unsigned char<code> buffer instead!<br />
<br />
Hope this helps :) <br />
<br />
Behind every great black man...<br />
... is the police. - Conspiracy brother<br />
<br />
<br />
<a href="http://www.codeproject.com/script/profile/whos_who.asp?id=418947&id=418947&df=100&forumid=27215&exp=6&select=1050632">Blog</a>[<a href="http://www.codeproject.com/script/profile/whos_who.asp?id=418947&id=418947&df=100&forumid=27215&exp=6&select=1050632" target="_BLANK">^</a>]
|
|
|
|
|
Hello,
I need to use CString because I use the VT_BSTR of VARIANT for using com port.
So could you tell me how to solve this problem or other method to do the com port program?
Please help!
Many thanks,
Alex
|
|
|
|
|
Hi Alex,
Try the following:
VARIANT var;<br />
CString str = "My serial data";<br />
var.vt = VT_BSTR;<br />
var.bstrVal = str.AllocSysString();
There's a lot written about serial programming here: http://www.codeproject.com/system/#Hardware+programming[^]
Hope this helps
--
Roger
|
|
|
|
|
Hi
Now I can send the data to com port in binary form,
CByteArray btArray;
int total;
total=GetDlgItemInt(IDC_EDIT1,NULL,TRUE);
btArray.Add(total);
COleVariant var(btArray);
m_comm.SetOutput(var);
VariantClear(&var);
but I can't receive in correct way.
Please help!
|
|
|
|