|
With pStrFinal = _tcsrev(pStrFinal); , you are messing your pointer away.
I recommend to use the MFC CString class instead (since you said it's a MFC dialog). This hides all this memory allocation mess.
|
|
|
|
|
Hi,
Regarding the technique of dumping in-memory statistics, is
given below
Note: memstate1 takes snapshot of pre-memory leak and
memstate2 takes snapshot of post-memory leak. finally,
memstate3 makes the statistics based on both the snapshots.
CMemoryState memState1, memState2, memState3;
void CHello::MakeMemoryLeak()
{
memState1.Checkpoint();
LPCTSTR strMemoryLeak = new char[50];
memState2.Checkpoint();
memState3.Difference(memState1, memState2);
memState3.DumpStatistics();
}
Hope this Helps
Regards
~Hari~
|
|
|
|
|
saravanaram wrote:
I get error when deleting pStrFinal...
So what's the error?
I suspect the problem lies within the following line, but can't know for sure without stepping through the code.
pStrFinal = _tcsrev(pStrFinal);
|
|
|
|
|
Hi David,
if you see the memory contents of (pStrWord), it contains
5 (CD - valid memory allocated) and 4 FD(padded memory, # may differ)
(Note: Assume that nStrLength is 5)
Following code lines, are writing on unallocated memory.
pStrWord[nWordIndex++] = ' '; //This causes the problem.
pStrWord[nWordIndex] = '\0';
_tcscat(pStrFinal,_tcsrev(pStrWord));
as well,
pStrFinal = _tcsrev(pStrFinal); //This assignment also causes the problem.
Actually, he has to allocate the extra one byte of memory to put the space character (' ').
Hopefully, I am right.
regards
~Hari~
|
|
|
|
|
|
Greetings. I'm using a VC++ 6.0 MDI to call a VC# form .dll. I exposed the VC# dll as a COM interface... n now I need to tell the VC# dll who's the daddy... but the VC# forms daddy should be a System.Windows.Forms.Form()... So i want to pass the handle of the VC++ 6.0 MDI app to a method from the VC#... it asks for an IUnknown... Please tell me how do i take the this->m_hWnd pass it through an IUnknow* and finally put it in a System.Windows.Forms.Form object... can this b done? is there a more friendly way? Thanks
NHM
|
|
|
|
|
If the only thing you need to pass is a window handle, then ::SendMessage(...) is probably the fastest way to achieve it. It does not require the COM interop you have mentioned.
|
|
|
|
|
how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#?
|
|
|
|
|
NHM wrote:
how can the VC# dll receive messages... in vc++6.0 PreTranslateMessage is the answer... n in VC#?
A Windows Forms app has a UI thread which processes windows messages just like any WIN32 app with a message loop. Any Windows Form control has a virtual WndProc method that can be overridden to respond accordingly.
The other way, a C# app can send a WIN32 message to any window (for instance a window from a VC++6 app) by using the [DllImport] P/Invoke technique :
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
|
|
|
|
|
if i override WndProc in the windows form (C# dll) then when i try to open it through the VC++ 6.0 App it stops execution... just gives a runtime error... ideas? thanks 4 your suport .S.Rod!
|
|
|
|
|
NHM wrote:
when i try to open it through the VC++ 6.0 App
What do you mean ?
Has it anything to do with the debug session ? Do you mean you are trying to access the C# WndProc implementation from your VC++ debug session ? No need to go further, you simply can't.
Or do you mean you are processing the message in the C# wndproc implementation and then it fails? If the code fails at this point, then it might be helpful for those listening if you post the code.
|
|
|
|
|
i've just overriden the WndProc... no code added to the base override...
this is what i have...
a) a vc++ 6.0 Mdi app (.exe)
b) a vc# dll with:
- class A (interface) (cominterop)
(i have to call some methods and access some properties)
- class B (windows form)
in the vc++ 6.0 mdi app i create an instance of classA
then i call a method from class A wich does this:
public void SomeThing()
{
Form1 f = new Form1();
f.Show();
}
and this is what i intended to do:
public void SomeThing( Form parent)
{
Form1 f = new Form1( Form parent);
f.MdiParent = parent;
f.Show();
}
i just want to say to the VC# winForm that his container is the VC++ 6.0 APP
what can i do?
|
|
|
|
|
The simplest thing that comes to my mind is to reparent the C# form window.
This can be done with simple things :
- the window handle of the C# form is obtained using this.Handle if you use managed code. Otherwise, from C++ code you can enum windows or use FindWindow(...) with a particular caption to get that window handle.
- then, use WIN32 ::SetParent(hwndForm, hwndNewParent /*MDIapp frame window hande*/) to reparent the form.
Good luck!
|
|
|
|
|
Hi,
I have a image control(child of main window) in a window,which is created with WS_CLIPSIBLING flag.
But when i move some other window over my main window. image control receives WM_PAINT message. How can i avoid receiving the WM_PAINT message for the image control?
|
|
|
|
|
I dont know any way to avoid recieving WM_PAINT but
you can ignore (comment code out) where you handle
the message.
jhaga
|
|
|
|
|
Why this generates "test.pmjaaaaYYYYY" as output??
<br />
<br />
<br />
<br />
<br />
char* szBuffer = NULL;<br />
int i = 0;<br />
<br />
CFile f;<br />
<br />
if( f.Open ("F:\\test\\id.txt", CFile::modeRead ) ){ <br />
try {
i = f.GetLength();
szBuffer = new char[i];
<br />
if(szBuffer != NULL)<br />
<br />
f.Read(szBuffer, i); <br />
f.Close();
<br />
} <br />
<br />
catch (CFileException *e) <br />
{ <br />
AfxMessageBox ("Error!"); <br />
e->Delete(); <br />
}
<br />
}
<br />
CString csPath = szBuffer;<br />
<br />
SaveStream(csPath);<br />
<br />
if(szBuffer != NULL) <br />
delete [] szBuffer;<br />
Thanks, Mark
|
|
|
|
|
The file you are reading won't have a 0 terminator. Try:
szBuffer = new char[i+1];
szBuffer[i] = 0;
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Now it works. Will a "Detected memory leaks!" be a problem?
Thanks, Mark
|
|
|
|
|
macmac38 wrote:
Will a "Detected memory leaks!" be a problem?
Short answer, Yes.
Also if you are reading a fixed length file, you should write using fixed length routines, not a stream. ie, don't mix file i/o types unless you have to.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Hi,
As, franks mentioned, it happens because, the output is not null-terminated. Here's the code snippet, which very well read your file, without any memory leaks.
-----------------------------------------------------------
CFile oFile;
DWORD dwFileLength;
if(oFile.Open("F:\\test\\id.txt", CFile::modeRead))
{
try
{
CString strBuffer;
dwFileLength = oFile.GetLength();
LPTSTR szBuffer = strBuffer.GetBufferSetLength(dwFileLength);
oFile.Read((LPVOID)szBuffer, dwFileLength);
oFile.Close();
CString csPath(strBuffer);
strBuffer.ReleaseBuffer();
}
catch(CFileException *e)
{
AfxMessageBox ("Error!");
e->Delete();
}
}
-----------------------------------------------------------
regards
~Hari~
|
|
|
|
|
Sorry if this is a silly question, but I'm a little confused.
I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application.
Ex:
In CMyAppDoc
CArray <<cmyclass,cmyclass>> m_myArray;
My question is.
How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view?
CMyAppView
?????
Best Regards
Dr. Pi
|
|
|
|
|
Hi,
i had the same problem and it seems to be impossible.
i created a lot of instances of my class with 'new' and than i stored the pointers in an CObList or CObArray.
This array stores only the pointers, so clean the memory up ('delete pClass') when deleting the array.
Dr-Kuulun
|
|
|
|
|
Try this:
CArray<CMyClass*,CMyClass*&> m_MyArray;
And to acces any data:
CMyClass* Temp = m_MyArray[i];<br />
Temp->DoSomething();
Hope this helps !
Ced
|
|
|
|
|
You are probably better off using the standardized std::vector class:
std::vector< CMyClass > m_myArray;
... now you can fill the vector e.g. using push_back()...
And now you can use
CMyClass c = GetDocument()->m_myArray[0];
to access the first data item in the associated document.
Hope this helps
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I have something similar in one of my projects.
class CMyDoc : public CDocument
{
public:
void GetAddressList( CDWordArray *pAddresses );
private:
CDWordArray m_arrAddresses;
};
void CMyDoc::GetAddressList( CDWordArray *pAddresses )
{
pAddresses->RemoveAll();
pAddresses->Append(m_arrAddresses);
}
void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
CMyDoc *pDoc;
CDWordArray arrAddresses;
pDoc = GetDocument();
pDoc->GetAddressList(&arrAddresses);
}
Hope this helps, or at least gives you an idea.
|
|
|
|