|
Hey, I tried that. But while compiling I am getting error:
error C2059: syntax error : ')'
I can't figure out why. Can u please help me?
|
|
|
|
|
Oh!
I looked at MSDN and found the correct way to use it.
The code should be as follows:
<code>
CMainFrame* mainFrame = dynamic_cast<CMainFrame*>(AfxGetApp()->m_pMainWnd);
mainFrame->doThisMemberMethod();
</code>
Thanks.
-- modified at 6:26 Sunday 17th June, 2007
|
|
|
|
|
Ooops. I copied the code from one of my own projects and had to rename things from my class name to CMainFrame. I accidentally erased <cmainframe *="">. Very sorry about that. Glad you still figured it out.
I ran into my own pet peeve of someone giving a code example which doesn't work.
|
|
|
|
|
Hmmm, strange. Apparently I did not erase it. It seems the forum is completely deleting my code. I just typed it again in my previous message and it does not show up in the post.
Somehow it worked when you typed it in your post. I wonder why.
|
|
|
|
|
StevenS_Dev wrote: It seems the forum is completely deleting my code.
No, it's there, albeit not shown. You are just failing to use the angle brackets above the smileys.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi everyone. This is my first post ever :P
I am currently programming a MSVC(no MFC), WIN98/WINXP, TaskManager-like application that enumerates all running processes through PE32, and displays total and hidden HWNDs per PID and running status. Options for killing a PID, show/hide/close hwnds are also available. So far so good.
This program detects via SendMessageTimeout any HWND that is not responding, but what about the ones without any HWNDs? How can I detect if a PID is not responding if it is windowless?
CTRL-ALT-DEL shows (not responding) for the hanged windowless process, and maybe I could use that as a workaround, but I do not know how to access this information either.
Three days so far in the web without success. HELP!!!
|
|
|
|
|
Dear all
who can provide any a cube class snippet? thanks...
Li Zhiyuan
5/10/2006
|
|
|
|
|
class Cube
{
}
What did you want it to do ? Sounds like homework to me.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: class Cube
{
}
It won't work, you forgot the ; after the class
|
|
|
|
|
You beat me to it!
Kevin
|
|
|
|
|
Your code is helpful but it has a problem why other elements are transparent ?
|
|
|
|
|
You asked this question previous and but you said cube can you more explain?
|
|
|
|
|
Hi,
In my application,we have the GraphicsView function, which displays number of graphics page.
I have 40 graphics page as page1,page2....etc.,.
I have the shortcut key to go for graphics main page as F5.
From that i have to move to 40 pages subsequently by pressing pagedown button are directly click next button in my graphics pages.
My problem is....when iam pressing the pagedown key...and if the pages reaches 30 or 32 pages one error is ooured like Out of Space.
When i searched for the error occurence..I got the PageFile Usage in my TaskManager is get increased and once it reached certain MB like morethan 500 MB it shows me this error.
I coded my pagedown functon as follows...
BOOL CGraphView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
UINT nChar = (UINT)pMsg->wParam;
UINT nKeyDown = (UINT)pMsg->lParam;
if((nChar == 33 || nChar == 34) && (nKeyDown == 21561345 || nKeyDown == 22085633))
{
short iTempPgNo = giSchPNo;
if(nChar == 33)
{
iTempPgNo--;
if(iTempPgNo < 0)
iTempPgNo = giSchPNo;
}
else
{
iTempPgNo++;
if(iTempPgNo >= iNoPages)
iTempPgNo = iTempPgNo - 1;
}
if(iTempPgNo != giSchPNo)
{
if(glg_animation[giSchPNo].GetSafeHwnd())
{
glg_animation[giSchPNo].ShowWindow(SW_HIDE);
giSchPNo = iTempPgNo;
((CMainFrame *)AfxGetMainWnd())->AddHistory(GRAPHIC,iTempPgNo);
}
}
return TRUE;
}
return CView::PreTranslateMessage(pMsg);
}
Here i know im coding only to hide the previous graphics page and not to destroy.So that only the memory get increased for each diaplay.
But i have OnDestroy() only after closing the entire graphicsView.
I donot know how to destroy the memory in that coding???Pls help me out.
Anu
|
|
|
|
|
Why, oh WHY, are you using PreTranslateMesssage() to read keystrokes?
You haven't even checked the MSG to see if is a keyboard message!
Maybe something like this...
ON_WM_KEYDOWN()
...
void CGraphView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == VK_PRIOR || nChar == VK_NEXT)
{
short iTempPgNo = giSchPNo;
if(nChar == VK_PRIOR)
{
iTempPgNo--;
if(iTempPgNo < 0)
iTempPgNo = giSchPNo;
}
else
{
iTempPgNo++;
if(iTempPgNo >= iNoPages)
iTempPgNo = iTempPgNo - 1;
}
if(iTempPgNo != giSchPNo)
{
if(glg_animation[giSchPNo].GetSafeHwnd())
{
glg_animation[giSchPNo].ShowWindow(SW_HIDE);
giSchPNo = iTempPgNo;
((CMainFrame *)AfxGetMainWnd())->AddHistory(GRAPHIC,iTempPgNo);
}
}
}
else
{
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
This may not fix your memory problems but it will make it easier to track for sure!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The code below will cause a heap error:
Error: HEAP[Core.exe]: Invalid Address specified to RtlFreeHeap( 00510000, 01CB45C8 )
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ThreadPool* pThreadPool = 0;
pThreadPool = ThreadHandlerEntry();
pThreadPool->Release();
return 0;
}
Inside pThreadPool->Release(), delete this is called, and that's where it fails. If I change the code to the below, where delete this has been taken out of pThreadPool->Release() and replaced with delete pThreadPool in WinMain(), it works.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ThreadPool* pThreadPool = 0;
pThreadPool = ThreadHandlerEntry();
pThreadPool->Release();
delete pThreadPool;
return 0;
}
Anyone know why this is?
|
|
|
|
|
A tricky one without the rest of the code but there are 2 basic things to check.
1. Double deletion. Is the code where you removed the delete ever possibly called twice.
2. Separate heaps. Is the code where you removed the delete in a Dll or library that may have it's own linked copy of the CRT and therefore it's own heap. This would mean any attempt to delete an object created in the main module would fail in this secondary module and would produce this error message. I've personally hit this on Windows CE where the rules may be sligthly different but I guess it can happen anywhere.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
This code is quite simple, so #1 is not the problem. #2 may be possible -- but what makes a DLL have its own heap? I thought the program managed the entire heap. That said, ThreadPool is in its own DLL, and WinMain compiles as the executable, so they are 2 different Visual Studio projects.
|
|
|
|
|
It's not the class that will have it's own heap it's the DLL. If you statically link a DLL to the CRT, e.g. LIBCMTD.LIB then the heap code get compiled into the DLL and it therefore gets it's own heap whenever it is loaded. If it's later used with an EXE that links to the CRT either statically or dynamically then they have 2 separate heaps.
If everything links dynamically then every module uses the one MSVCRT.DLL loaded into the process and they all share the one heap. It sounds like a plausible cause for your error if ThreadPool is in its own DLL. I'll try a little ASCII art as I'm not that good at explaining it.
--MY.exe Process space in memory--
[
{
//Main function is here
//new or delete here uses late bound MSVCRT.Dll
}
--Kernel32.Dll--
--OtherWindows.Dll--
--ThreadPool.Dll--
[
{
//ThreadPool code is here
//new or delete here is fixed at compile time to call LIBCMTD code linked in below
}
LIBCMTD.LIB link inserts CRT code here
{
//ThreadPool.Dll is early bound to this code so it uses this heap
//Heap code is here
}
]
--MoreWindows.Dll--
--MSVCRT.Dll--
{
//This dynamically linked code is used by MY.exe which binds to it after it's loaded
//Heap code is here
}
]
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Well, I don't exactly want to combine the two together, since ThreadPool should be its own component (and used by other classes as well). This is what I tried and it does fix the problem (as well as the source of the problem).
Given that I call pThreadPool->Release(), it would only make sense to somehow acquire the ThreadPool object from the ThreadPool class itself, so I just created the following static function from within the ThreadPool:
ThreadPool* ThreadPool::Create()
{
ThreadPool* pThreadPool = new ThreadPool();
return pThreadPool;
}
Thanks a lot for your help, Matt. I always used to think the "heap" was one global section of memory that the entire process handled, and that any new or delete would dump things onto that heap. It seems like the concept is not so simple and there can be multiple heaps...
|
|
|
|
|
I give the following advice about once a month (recently every few days); it often helps me track down the nastier heap errors:
Try enabling the page heap[^] for your process. Follow these steps:
1. Download and install WinDBG[^].
2. Select “Start”->“All Programs”->“Debugging Tools for Windows”->“Global Flags”.
3. Select the “Image File” tab.
4. In the “Image: (TAB to refresh)” edit control enter the name of your app then press TAB. Just the name with the extension; not the full path.
5. Tick the following:
- “Enable page heap”
- “Enable heap tail checking”
- “Enable heap free checking”
- “Enable heap parameter checking”
- “Enable heap validation on call”
- “Create user mode stack trace database”
6. Press “Apply”.
7. Debug your application. Any debugger will do but with WinDBG you have access to the stack traces of allocations via the !heap –p –a command, for example. When a heap problem is detected a breakpoint will be generated.
8. When done un-tick all the options you ticked, press “Apply” then dismiss GFlags. This step is important as if it’s skipped all applications named as entered in step 4 will run with the page heap enabled.
Note that when using the page heap your application will run much slower than normal and consume way more memory. It’s good to have a beefy machine to do such tests; and such tests should be ran regularly on all applications you develop as part of regular testing activities. If I find a part of my application that’s too slow with the page heap enabled I optimize the memory allocation in that region.
Steve
|
|
|
|
|
Hey Steve,
I have fixed the issue and it was likely what Matthew mentioned.
Thanks though.
|
|
|
|
|
Please help me.. i need animation which create with Visual C++,
like brush animation or just line can move ... need help plis
|
|
|
|
|
san_sui wrote: animation which create with Visual C++,
Can you more explain?
|
|
|
|
|
i am trying to add the following function as public in my wNode class. my intention is to have a function that returns a two dimensional character array (basically an array of strings and ids)...this is the way i do it:
char[][] getContentArray();
it is giving me a compiler error -> error C3409: empty attribute block is not allowed
what's wrong?
-- modified at 19:19 Friday 15th June, 2007
--
dg
|
|
|
|
|
moonraker928 wrote: char[][] getContentArray();
You'll likely need to use:
char* getContentArray(); or
char** getContentArray();
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|