_CtrIsValidHeapPointer(pUserData) problem

I have made a connection to the sql server using ADO within a DLL function. It wokrs fine...

However when I stop my application it prompt an error
File: dbgheap.c
Line: 1011
Expression: _CtrIsValidHeapPointer(pUserData)

Why should this happen?
I am sure I have close the db connection and set the _RecordSetPrt and _ConnectionPrt to NULL


jabbaaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
georgiek50Connect With a Mentor Commented:
I had lots of trouble with this one in the past.  It turns out that the reason for the crash and bug report was that I was trying to free memory again, meaning that the memory had already been freed from the pointer previously so trying to do it again resulted in the crash.  Look through your code to make sure you are not deleting twice.
0
 
may_f_24Commented:
can you upload the code in which you create the connection and the code for closing it?
0
 
jabbaaAuthor Commented:
The code I am using just as follows:
Thanks




#include <stdio.h>
#include <afxdisp.h>
#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                 if (FAILED(_hr)) _com_issue_error(_hr); }

#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
   InitOle()  { ::CoInitialize(NULL); }
   ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE

void main(){
   _RecordsetPtr   spRS;
   _ConnectionPtr  spCON;
   try{
       CREATEiNSTANCE(spCON,Connection);
       spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;UID=sa; PWD=;";
       // spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=authors.MDB;DefaultDir=C:\\test;";
           
       spCON->Open( "", "", "", -1 );
       CREATEiNSTANCE(spRS,Recordset)
       spRS->PutRefActiveConnection( spCON );
       spRS->Open("select au_lname, au_fname from authors",
              vtMissing, adOpenKeyset,
           adLockBatchOptimistic, -1
         );
       while(spRS->adoEOF == false){
           printf("au_lname = %s  au_fname = %s \n",
                   UC _bstr_t(RsITEM(spRS,0L)),
                   UC _bstr_t(RsITEM(spRS,"au_fname"))
              );
           spRS->MoveNext();
       }
       spRS->Close();
       spCON->Close();
   }
   catch( _com_error &e){
       _bstr_t bstrSource(e.Source());
       _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
           + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
           + _bstr_t(e.Description());
       
       MessageBox(0,bs,bstrSource, MB_OK);
   }          
}
0
 
may_f_24Commented:
look at this page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__crtisvalidheappointer.asp

debug your application, and when it's sopt on that line, go back on the stack to see the command and pointer which cause the problem.
0
All Courses

From novice to tech pro — start learning today.