|
Hi,
I have a Visual Studio 2008 MFC doc/view application. I have choosed a docking pane type. The dock is a tree control like Windows explorer. When I click an item on the tree, I want to change the form in the view area.
For that I have to acces the document to get a member function. The code is working but I get memory leak.
Perhaps I don't take the good way.
Any suggestions ?
Claude
Here's my code:
void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
*pResult = 0;
CString strItem;
HTREEITEM hItem = GetSelectedItem();
strItem = GetItemText(hItem);
// Pointeurs vers le document
CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
CCDSView* pView;
pView = (CCDSView*)pFrameWnd->GetActiveView(); //
// Detected memory leaks!
//Dumping objects ->
//{1272} normal block at 0x03E2C478, 530 bytes long.
// Data: < 6 > 14 36 19 01 0F 00 00 00 00 01 00 00 01 00 00 00
//{1190} normal block at 0x03E28F20, 530 bytes long.
// Data: < 6 ( > 14 36 19 01 28 00 00 00 00 01 00 00 01 00 00 00
//Object dump complete.
CCDSDoc* pDoc = pView->GetDocument();
pDoc->ToDoc(strItem);
}
|
|
|
|
|
The code that you have shown does not appear to have any memory leaks.
Search for the new keyword or functions like HeapAlloc , GlobalAlloc , VirtualAlloc etc. in all the code. Then you can see if the allocated memory is being freed.
Alternatively you can use the _CrtMemCheckpoint and _CrtMemDifference functions to find exactly where the memory leak happens.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
How do you know there is a memory leak? Is the debugger dumping the objects after your application shuts down? In which case it must point out the line numbers where the leaking memory was allocated. If not, you need to add this to the beginning of your manually created source files (if a source file is added by any of the wizards, it adds this by default):
#ifdef _DEBUG
#define new DEBUG_NEW
You may look at the definition of DEBUG_NEW to see what it does.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
See this page[^] (or this page[^] for newer versions of Visual Studio) for advice on how to get a debugger breakpoint when the allocation that's been detected as leaking occurs.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
When I tried to compile my files, every file will generate following errors. After commenting the "#include "stdafx.h" out, these two errors will disappear. My "debug" version can compile. but the "release" version has following problems.
I used VS to create a new project. I got same errors. The debug version is OK. The release version can not be compiled.
1>C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.inl(210) : error C2556: 'CFile *CArchive::GetFile(void) const' : overloaded function differs only by return type from 'CFile &CArchive::GetFile(void) const'
1> C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.h(1628) : see declaration of 'CArchive::GetFile'
1>C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.inl(210) : error C2372: 'CArchive::GetFile' : redefinition; different types of indirection
1> C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.h(1628) : see declaration of 'CArchive::GetFile'
What is wrong?
Thanks,
modified on Friday, May 15, 2009 5:47 PM
|
|
|
|
|
Sure the header file hasn't been edited somehow? Both my afx.h and afx.inl (from VS2008, not VS2005, but I can't see them changing) have CFile *CArchive::GetFile(void) const
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I used VS to create a new project and compiled the release version. I also got these error messages. I am trying to re-install VS.
Thanks,
|
|
|
|
|
Hi,
I am having a problem declaring and passing a multidimensional array of floats as an argument to a function. Can someone help me with this problem? My code is enclosed.
Any help appreciated.
float* pData = new float[nNumRows,2];
for( int i = 0; i < nNumRows; i++ )
{
pData[i][0] = ((CSodSpecData*)pOdbSpecData)->m_cvData[i].Real();
pData[i][1] = ((CSodSpecData*)pOdbSpecData)->m_cvData[i].Imag();
}
lErrorCode = pService->serviceNotifyDataEventSet( pData[0], strSensorName );
CDFstatus CABCDEntryPointService::serviceNotifyDataEventSet(float* dataSet, const CString& varName)
|
|
|
|
|
Royce Fickling wrote: I am having a problem declaring and passing a multidimensional array of floats
Without knowing what that method requires at the address sent as the first parameter all I can offer is this will compile. No way to know if is correct.
pService->serviceNotifyDataEventSet( pData, strSensorName );
or
pService->serviceNotifyDataEventSet( &pData[0], strSensorName );
|
|
|
|
|
Royce Fickling wrote: float* pData = new float[nNumRows,2];
Should this be:
float pData = new float[nNumRows][2];
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi
I want to add wide char support to my software. If I do this, I will need to change a lot of code. If the software is changed to wide char, does this wide char software can handle ANSI char as it used to be?
Is there any advice or good experience?
Thanks,
|
|
|
|
|
See [^].
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]
|
|
|
|
|
|
Rajesh R Subramanian wrote: Note that everything is represented as Unicode, in an application that is built for Unicode.
Not at all true.
"Hello World" is an ANSI string, even in a application build with UNICODE libraries.
L"Hello World" is the UNICODE string in either environment.
_T("Hello World") varies.
Even the underlying API has both Wide and Ansi versions. Sometimes the strings in these are converted. Other times they are not.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote: "Hello World" is an ANSI string, even in a application build with UNICODE libraries.
L"Hello World" is the UNICODE string in either environment.
I wouldn't expect anyone reasonable to define strings like this, unless for a debate. My point was that he should not be including ANSI stuff into an Unicode application (why not Unicode?), as that might bring down the performance.
I assume the usage of generic text mapping routines and I could have specified it clearly. Does my comment make sense if string literals enclosed within the TEXT macro?
Rajesh R Subramanian wrote:
Also, if you write an application in ANSI, Windows will still have to convert everything to Unicode internally to work with it. So, theoretically your application must be faster if it is built for Unicode.
Joe Woodbury wrote: Even the underlying API has both Wide and Ansi versions. Sometimes the strings in these are converted. Other times they are not.
It wasn't clear enough that I told "Windows" and not APIs? An API may have both versions, but when it has to pass on a string to Windows, it must be converted to Unicode. Even if a function returns an ANSI string, again, Windows actually returns a Unicode string and there happens another conversion which is not visible to the user calling the API and essentially the performance goes down.
It is a crappy thing, but it's life -^ Carlo Pallini
modified on Sunday, May 17, 2009 2:40 AM
|
|
|
|
|
I have a COM ATL based exe server that supposed to to be a single instance. It generally runs as a windows service. However when I debug it ti doesn't act the way I'd expect. I start it in the debugger. I then have a php script that gets executed by the apache webserver. This php script creates a COM object that is vended out by my COM server. However instead of using the instance of the server that I have running, a new instance is started up, in what appears to be the System account. Is this some weird permissions rule, that because the script is being executed by a process running as a service, that COM creates a second exe server instance in the same security context? Is there way around this? Or is there something blindingly obvious that I'm missing?
|
|
|
|
|
Yes, out of process COM communication is basically permitted only if both sides run in the same security level (if I get it correctly )
Anyway, here is a workaround[^] according to the COM people at MS.
|
|
|
|
|
Nemanja Trifunovic wrote: according to the COM people
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]
|
|
|
|
|
Who are now kept in a small room with no windows and fed corn syrup and creamed spinach. Once a day they are allowed to hold hands and sing "Won't you be my IMoniker?"
|
|
|
|
|
|
CPallini wrote: interperabilty
Italish, Carlo?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Actually a typo (of a poor Italiansh guy... ).
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]
|
|
|
|
|
Thanks, that's a great link. It does have the unfortunate side effect of making me want to jab a fork in my eye. What a frigging mess
|
|
|
|
|
Jim Crafton wrote: Thanks, that's a great link. It does have the unfortunate side effect of making me want to jab a fork in my eye.
Pretty normal while working with COM if you ask me.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|