|
Hi all,
I am writing a simple application in VS.NET 2003 which uses my own dll (vz.dll). The dll is for my C++ library which the application uses. See the scenario below:
app (my own application) --> uses vz.dll (a C++ API exporting its class functions, my own classes). I am building the DLL with /MTd flag enabled rather than using flag /MDd. Also I am calling the constructor within the DLL with new.
Debugging the application, when I exit the application I do deletion of my data(calling delete on an instance created using new) I get the following exception with the stack trace
Unhandled exception at 0x7c822583 in app.exe: User breakpoint
ntdll.dll!7c87512a()
ntdll.dll!7c8754d1()
ntdll.dll!7c8409a8()
kernel32.dll!77e6b28e()
kernel32.dll!77e755b9()
vzclient.dll!_CrtIsValidHeapPointer(const void * pUserData=0x01da27a0)
Line 1807 C
vzclient.dll!_free_dbg_lk(void * pUserData=0x01da27a0, int nBlockUse=1)
Line 1132 + 0x9 C
vzclient.dll!_free_dbg(void * pUserData=0x01da27a0, int nBlockUse=1)
Line 1070 + 0xd C
vzclient.dll!operator delete(void * pUserData=0x01da27a0) Line 54 +
0x10 C++
vzclient.dll!vzTMRenderAction::`scalar deleting destructor'() +
0x3c C++
app.exe!CleanVolumizer() Line 438 + 0x34 C++
I commented out the deletion of the data which was causing this. After which I am still getting the same exception
Unhandled exception at 0x7c822583 in app.exe: User breakpoint.
But now the location of exeption has shifted to dbgheap.c when the _CrtIsValidHeapPointer returns.
Though it seems to me a heap corruption but I have no clue why it is happening and where. I also tried using gflags utility but not of much use.
Please help me, I am stuck.
Any help/ suggestion is welcome.
Thanks in advance,
Divick
|
|
|
|
|
Could it be that you are using 'new' in a release-built dll and 'delete' in a debug-built app?
--
Roger
|
|
|
|
|
Hi thanks for the reply. Well I have rechecked that, it is not the case. I am using same version for both (debug and release), but yes there is another third party dll that I am using for both the release and debug versions.
Another thing that I wanted to mention was that the problem occurs only with the DEBUG versions of the application and dll but not with the RELEASE versions.
Since to me what it feels like a heap corruption issue, I seriously doubt that if the error is not showing up now, then it won't show up later.
Any ideas about this.
Thanks a lot for your reply,
Divick
|
|
|
|
|
Well, there's nothing to do but get your fingers dirty and do some serious debugging on the pointer that is being freed.
There's no way of telling you anything more about what could be wrong, you're on your own here.
I suggest you TRACE the value of the pointer when it's getting initalized ('new'), TRACE it again when the application is running and TRACE it a third time when it's about to be freed ('delete').
The pointers written to your debug window should be the same, but they most likely won't be.
This is to find out whether the pointer gets overwritten, or altered, in the startup sequence or when closing the application in order to isolate the failure.
--
Roger
|
|
|
|
|
Are you using static or dynamic CRTL? If you are using static, then you might be running into the problem where you are allocating memory in the DLL and then trying to free it in the EXE. Or visa-versa. With a static CRTL, you will have two heaps in existance, the one in your DLL and the one in your EXE. You can't allocate memory in one and then free it in another.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi,
thanks for the reply. I think I am using the static CRTL(rather MSVCRT.dll, the C++ Run time library specified using the /MT flag rather than the /MD thread). But I am deleting the data within the application which is where I create it.
Further debugging into the code I have found that checking the validity of the pointer with assert and _CrtValidHeapPointer in the application does not create any problem but checking that within the DLL causes an exception. See the code snippet below;
//---------application code
MyOwnClass * myOwnPtr = new MyOwnClass();
//new and deletion is being done in the application only
_ASSERTE(_CrtIsValidHeapPointer(myOwnptr));
_ASSERTE(_CrtIsValidPointer(myOwnptr,sizeof(myOwnptr),true));
delete myOwnptr;
//-----------------DLL code
MyOwnClass()::~MyOwnClass()
{
_ASSERTE(_CrtCheckMemory());
//////////////////////////////////
//This causes a pop up box with the following message unhandled exception at 0x7c822583 in app.exe: //User breakpoint. and takes the debugger to dbgheap.c file
//////////////////////////////////
_ASSERTE(_CrtIsValidHeapPointer(this));
}
Even if I comment the code for assertion of this pointer in the above destructor then again when the destructor returns the same exception is thrown in dbgheap.c
Does it clarify my question a bit more?
Thanks for your help,
Divick
|
|
|
|
|
One more update to this one. Changing my application as well as DLLs to compile as /MDd (i.e. as multithreaded DLL , yeah the application as well) eliminated the error completely.
Though I understand that with /MT the C run time is linked statically and with /MD the CRT is linked dynamically (correct me if I am wrong) but I am really wondering why at all should it create problem with memory allocations at all?
Second I always thought that /MD is only for DLLs while it is also applicable to applications as well. Should one always be using the flag /MD for building all kind of applications?
Any ideas / suggestions are welcome.
Thanks,
Divick
|
|
|
|
|
Often we have seen html buttons which can launch AIM chat clients from the browser
Sample code for AIM
location.href = "aim:goim?Screenname=" + [Whatever] + "&Message=" + message + "Hey+Wassup...";
Basically its true for all the apps like Microsoft Word (doc), pdf, outlook etc etc
Does anyone know how to launch googleTalk from browser
Thank you
Shrek
|
|
|
|
|
Often we have seen html buttons which can launch AIM chat clients from the browser
Sample code for AIM
location.href = "aim:goim?Screenname=" + [Whatever] + "&Message=" + message + "Hey+Wassup...";
Basically its true for all the apps like Microsoft Word (doc), pdf, outlook etc etc
Does anyone know how to launch googleTalk from browser
Thank you
Shrek
|
|
|
|
|
You need to setup a protocol handler i.e. similar to aim: for AIM chat, similarly there is a handler for yahoo too.
If googletalk had not implemented that, then you cant do it but if you can setup your own handler and lauch google chat it can be done.
I am not too experienced in this topic, but this would give you some hints on wht to look for.
-prakash
|
|
|
|
|
I want to draw the gradient of 3 colors with rotaion as dialog background. It just looks like:
1111111111111#############
111111111111#############$
11111111111#############$$
1111111111#############$$$
111111111#############$$$$
11111111#############$$$$$
1111111#############$$$$$$
111111#############$$$$$$$
11111#############$$$$$$$$
1111#############$$$$$$$$$
111#############$$$$$$$$$$
11#############$$$$$$$$$$$
1#############$$$$$$$$$$$$
#############$$$$$$$$$$$$$
The different characters mean different colors.
The color and the rotaion are specified by user.
Please explain as detailed as possible if you have some good ideas because I am not good at graphics.
Thanks for your help!
|
|
|
|
|
|
Good day,
I'm reposting my problem since i havent got an answer. I have a two dialog(main, child), the main is the normal dialog when you start to create a dialog application in EVC. The child dialog is a modeless dialog here is how the child is called.
CMyChild* childform=new CMyChild(this);
childform->Create(CMyChild::IDD);
childform->ShowWindow(SW_SHOW);
The child also has a public function UpdateProgress bar which updates the progress bar of child dialog. I have also a function in child dialog which updates the text much the same as updating the progress bar. here is how it is called.
CMainDlg::MyMainFunc()
{
CMyChild* childform=new CMyChild(this);
childform->Create(CMyChild::IDD);
childform->ShowWindow(SW_SHOW);
childform->UpdateProgress(10); //updates the progress bar by 10 steps..
childform->UpdateProgressStatusText("Loading 10%"); // updates the static text But doesnt work..
childform->UpdateProgress(210); //updates the progress bar by 10 steps..
childform->UpdateProgressStatusText("Loading 20%"); // updates the static text But doesnt work..
}
I'm sure that I change IDC_STATIC to IDC_LOADINGTEXT so id will not be the issue. My problem is why is that progress bar is updated with what i pass but UpdateProgressStatus is not updated with the text that I pass?
Here is the two child functionss.
void CMyChild::UpdateProgress(int pStep)
{
m_ctrlProgress.SetPos(pStep);
}
void CMyChild::UpdateProgressStatusText(char* text)
{
CString tmp;
tmp=text;
GetDlgItem(IDC_LOADINGTEXT)->SetWindowText(tmp);
}
Im sure that i set the property of IDC_LOADINGTEXT to visible. Still why is that the modeless dialog is not updated with the text I pass and the progress bar is updated.??
Pls. Help.
Thanks.
|
|
|
|
|
hi,
I am not an expert but i have experinced through your knid of problem.
here when you create the dialog box, you see there is an option redraw in its properties. Try executing it after changing the redraw property to no redraw.
If then also it doesn't work, following is the solution (This is what i used).
what i did was i created the modeless dialog box in the main thread and started a new thread. this new thread will do the work i wanted and then it calls the incrementprogress function of the dialog box class. Now the problem here is in the thread the dilog object wont be visible. to do this
1. easiest, you can delare the dialog object golbal.
2. recomended, you pass the object reference(this pointer) to the thread parameters.
Tell me if it works, an ya don't forget to rate it.
|
|
|
|
|
Hello,
I found another way to solve my problem though it may be not a solution to CStatic problem but this can be a work-around of displaying a progress text status. Though i have solve my own problem still I want to share info so that if someone encounter this problem, He/She may try our solutions (By No Redraw Sol., or By Thread Sol , or By Drawing Text Solution.).. Here is how I display the status to the child modeless dialog.
void child::UpdateStatusMessage(char* pmessage)
{
CString strmsg;
strmsg=pmessage;
CDC* cDC=GetDC();
CFont HeaderTitle;
RECT r;
HeaderTitle.CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,0,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,
_T("Arial"));
r.top=120; r.bottom=140;
r.left=30; r.right=100;
cDC->SelectObject(HeaderTitle);
cDC->DrawText(strmsg,&r,DT_NOCLIP);
ReleaseDC(cDC);
}
Thanks.
|
|
|
|
|
hey buddy you need not do all this.
just Change the ID of the static message from IDC_STATIC to anything else (IDC_TEXT).
now go to class wizard and add a CString variable (msg) for IDC_TEXT.
now when ever you want to update it just say
<code>UpdateData(true);
msg="new messgae"
UpdateData(false);</code>
Tell me if it works, yaa don't forget to rate it.
|
|
|
|
|
well if u don't know much threading then you are same as i was a month back.
For threading search codeproject articles ( i don't have collection of it to tell you).
any way i will paste my code here if you can make sense out of it.
DlgProgress *dlglocprog;
DWORD WINAPI PseudoThreadFunction( IN LPVOID vThreadParm )
{
CMainFrame* pThreadParam = ( CMainFrame* ) vThreadParm;
pThreadParam->FunctionClients();
return 1;
}
bool CMainFrame::ExecuteLocateThread(void)
{
HANDLE hThread = NULL;
DWORD dwThreadID = 0;
int nTimeout = 5000;
try
{
hThread = CreateThread( NULL,
0,
PseudoThreadFunction,
this,
0,
&dwThreadID );
}
catch( CException* )
{
return false;
}
bool bFinished = false;
do
{
DWORD dwWaitResult = MsgWaitForMultipleObjects(
1,
& hThread,
FALSE,
nTimeout,
QS_ALLEVENTS | QS_SENDMESSAGE);
switch ( dwWaitResult )
{
case WAIT_OBJECT_0 :
case WAIT_ABANDONED_0 :
{
bFinished = true;
break;
}
case WAIT_OBJECT_0 + 1 :
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) == TRUE )
if ( !AfxGetApp( )->PumpMessage( ) )
{
::PostQuitMessage( 0 );
}
break;
}
default :
{
bFinished = true;
}
}
} while ( ! bFinished );
return true;
}
void CMainFrame::FunctionClients(void)
{
for(unsigned short addr=1;addr<256;addr++)
{
vi_Progress=addr;
dlglocprog->IncrementProgress();
Sleep(10);
}
dlglocprog->EndDialog(0);
b_LocateProgress=false;
}
void CMainFrame::OnClientoptionsLocateallactiveclients()
{
if(!b_LocateProgress)
{
b_LocateProgress=true;
dlglocprog = new CLocateProgress();
dlglocprog->Create(IDD_LOCATING_CLIENTS);
dlglocprog->ShowWindow(SW_SHOW);
dlglocprog->CenterWindow(this);
p_LogView->DisplayData("");
p_LogView->DisplayData("Locating all active clients...");
ExecuteLocateThread();
}
}
void ProgressDlg::IncrementProgress(void)
{
c_Progress.SetPos(vi_Progress);
UpdateData();
m_ProgressCount=c_Progress.GetPos();
UpdateData(false);
}
Tell me if it worked, an yaa don't forget to rate it.
|
|
|
|
|
i wnat to create a file to store a list of ids and name.
the logic should be such that when i give id it should return name.
so what kind of storage format i should go for to make my retrival easy.
|
|
|
|
|
Unless you are not willing to use any fancy database approach and run some queries,
you could go for an ASCII file, in which each line could contain text like:
22-Name
where the id is followed by a "-" and the name itself.
Then you use a CStdioFile object to read the file line by line.
Assuming now that you get the line info into some
char chText[256] variable, you go then for something like this:
<br />
char chName[256];<br />
unsigned int ID;<br />
sscanf(chText, "%u-%s", &ID, chName);<br />
As soon you get the ID value you are looking for, you stop the process of reading the file, close the file and return chName
I'm pretty sure, some other ways exist as well )
SkyWalker
|
|
|
|
|
|
I use the tecnique show in this article this is working fine in vc++ of visual studio 6, but in vc++ of visual studio the file is not stored properly.
How should i serialize and store my data
i want this to be done for a class derived from CDialog class.
Thanks for your time.
|
|
|
|
|
oh god i am really sorry,
I found the error.
When i inserted the serialization using the class wizard it inserted the code as follows
if (ar.IsStoring())
{
ar >> m_strName;
ar >> m_nIndex;
}
else
{
ar << m_strName;
ar << m_nIndex;
}
note IsStoring there.
and in the article the same function is as follows
<code>
if (ar.IsLoading())
{
ar >> m_strName;
ar >> m_nIndex;
}
else
{
ar << m_strName;
ar << m_nIndex;
}
</code>
note IsLoading here.
My mistake was i used the wrong indirection. Make a note of it and never do such a stupid mistake. I wasted 5 hours on this.
|
|
|
|
|
karmendra_js wrote:
I wasted 5 hours on this.
It was only a waste if you failed to learn anything from the experience.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
i have written a project in VC++ that creates reports for my compnay. but this application only allows one page. how do i code it, so that it support any no. of pages we want.
nams
|
|
|
|
|
In the print structure, set the number of pages to 2 or more.
The print page loop will run for each page#.
BOOL MyView::OnPreparePrinting(CPrintInfo* pInfo)<br />
{ <br />
int nPages = CalculateRequiredPages();<br />
pInfo->SetMaxPage(nPages);<br />
<br />
<br />
BOOL bRet = DoPreparePrinting(pInfo);<br />
pInfo->m_nNumPreviewPages = 1;<br />
<br />
return bRet;<br />
}
No see-you, no heal-you. Ptthh.;P - Der Dokter
|
|
|
|