Link to home
Start Free TrialLog in
Avatar of jabbaa
jabbaa

asked on

_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


Avatar of may_f_24
may_f_24

can you upload the code in which you create the connection and the code for closing it?
Avatar of jabbaa

ASKER

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);
   }          
}
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.
ASKER CERTIFIED SOLUTION
Avatar of georgiek50
georgiek50

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial