|
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
|
|
|
|
|
<<<<<<<<<<<< NVM - I GOT IT TO WORK! >>>>>>>>>>>>
still doesnt work..
this is what i have: (i have changed the header file appropriately)
char** workflow::getContentArray()
{
char content[5][5];
return content;
}
error C2440: 'return' : cannot convert from 'char [5][5]' to 'char **' -> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
-- modified at 23:40 Friday 15th June, 2007
--
dg
|
|
|
|
|
moonraker928 wrote: char** workflow::getContentArray()
{
char *content[5][5];
return content;
}
Why would you want to do this? content is no longer valid once getContentArray() goes out of scope. Try:
char* workflow::getContentArray()
{
char content = new char[5][5];
return content;
}
"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
|
|
|
|
|
I am getting this error when I build my project.
error LNK2019: unresolved external symbol __imp__wprintf
I know that means I am linking to the wrong library. I think this is in the runtime library. I've tried the various settings (Multithreaded debug, Multithreaded debug dll) as well as all the other options. Some, of course cause many more errors, none make this one go away.
Please help. Thanks in advance for any advice.
Regards, Bill
|
|
|
|
|
Hi Bill,
I guess, you have "Ignore All Default libraries" option selected. Unselect this option. Go to project settings and choose Link option and uncheck the Ignore All default libraries check box (if you are using VS2003 and above, choose No in the list. The name of the item is same).
Hope that helps.
Kiran.
|
|
|
|
|
Hi Kiran,
Thanks for the reply.
Unfortunately, the developer on this project had already tried that setting:
Ignore All Default Libraries = No.
He also tried changing the Ignore Specific Library setting. He tried setting the ignore list to: LIBCMT;MSVCRTD;LIBC;msvcrt and received a large volume of errors. Also clearing the list resulted in errors. He finally reverted to the original list: MSVCRTD
If you have any more thoughts, I would appreciate hearing from you again. We are starting to fall behind on the project over this issue.
Thanks, Bill
Regards, Bill
|
|
|
|
|
hi all..
i want to write a class for which a private data member is an instance of that same class..
for example:
class wNode {
private:
wNode next;
wNode previous;
...
}
this should be a very standard thing to do - i can do it in java just fine. in c++, it gives me compiler error c2460.
how do i go around this or fix this to accomplish my goal??
thanks!
dg
--
dg
|
|
|
|
|
Define a pointer to the class, not an actual instance. That's what Java does even if the notation may confuse you to think otherwise.
class wNode {
private:
wNode* next;
wNode* previous;
...
}
|
|
|
|