|
 |
activex_data_objects thread: Unhandled exeption?
Message #1 by "Reed Mohn, Anders" <Anders.Reed.Mohn@i...> on Thu, 14 Jun 2001 14:07:11 +0200
|
|
I am pretty new at this, so please bear with me ..
When I run this piece of code (code sample 1, below),
the call to CreateInstance() fails.
Somewhere in the CreateInstance-function,
there's a call to function CoCreateInstance().
(note: I left out function parameters in the text, just to save typing)
Seems like this call is not executed (the error that comes
back is: "CoCreateInstance not executed", and when tracing,
VC++ doesn't step into that function).
It then goes back to my original program,
on to the exeption handling, and calls the function
PrintProviderError() (code sample 2)
The line
if( (pConnection->Errors->Count) > 0)
causes and exeption in COMIP.H (code sample 3)
A check for
(m_pInterface == NULL) is true, and COMIP.H
issues a COM error (E_POINTER).
This is where the debugger says:
Unhandled exeption in moset.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++
Exception.
Can anyone tell me what's missing? Frankly, I don't understand what
situation that causes
this in the first place.
-What does CoCreateInstance do anyway?
-Where should m_pInterface have been assigned a value?
-Anyone have a reference to something I should read, to understand this
better?
Any help appreciated!
Cheers,
Anders RM :=)
Code sample 1 (EPAY.C):
static int CreateTransactionRecord(char *chTransactionType, const char
*szHost, const char *szBrandID)
{
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstTransactions = NULL;
// Define connection string.
_bstr_t strCnn("Provider=sqloledb;Data Source=sylvester;"
"Initial Catalog=testdb;User Id=******;Password=******;");
IADORecordBinding *picRs = NULL; // Interface Pointer declared
CTransactionRs transactions; // C++ Class object.
char szTimestamp[20]; //Buffer to hold timestamp
LogTrace(3, "DB-operasjon");
try
{
// Get current date and time
GetTimestamp(szTimestamp);
// Open a connection.
// This is where it all goes to ****
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
.....
.....
.....
} catch(_com_error &e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection);
PrintComError(e);
}
return ERR_SUCCESS;
}
Code sample 2 (EPAY.C):
/* *********************************
** PrintProviderError
** *********************************/
void PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
if( (pConnection->Errors->Count) > 0) // Here is where it chrashes
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("Error number: %x\t%s\n", pErr->Number,
(LPCSTR) pErr->Description);
}
}
}
Code sample 3 (COMIP.H):
// Allows this class to be used as the interface itself.
// Also provides simple error checking.
//
Interface* operator->() const throw(_com_error)
{
if (m_pInterface == NULL) {
_com_issue_error(E_POINTER);
}
return m_pInterface;
}
Message #2 by Thomas Bellavia <TBellavia@V...> on Thu, 14 Jun 2001 08:42:27 -0400
|
|
Did you first call :
::CoInitialize(NULL);
before instantiating com components in your application?
-----Original Message-----
From: Reed Mohn, Anders [mailto:Anders.Reed.Mohn@i...]
Sent: Thursday, June 14, 2001 8:07 AM
To: ActiveX_Data_Objects
Subject: [activex_data_objects] Unhandled exeption?
I am pretty new at this, so please bear with me ..
When I run this piece of code (code sample 1, below),
the call to CreateInstance() fails.
Somewhere in the CreateInstance-function,
there's a call to function CoCreateInstance().
(note: I left out function parameters in the text, just to save typing)
Seems like this call is not executed (the error that comes
back is: "CoCreateInstance not executed", and when tracing,
VC++ doesn't step into that function).
It then goes back to my original program,
on to the exeption handling, and calls the function
PrintProviderError() (code sample 2)
The line
if( (pConnection->Errors->Count) > 0)
causes and exeption in COMIP.H (code sample 3)
A check for
(m_pInterface == NULL) is true, and COMIP.H
issues a COM error (E_POINTER).
This is where the debugger says:
Unhandled exeption in moset.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++
Exception.
Can anyone tell me what's missing? Frankly, I don't understand what
situation that causes
this in the first place.
-What does CoCreateInstance do anyway?
-Where should m_pInterface have been assigned a value?
-Anyone have a reference to something I should read, to understand this
better?
Any help appreciated!
Cheers,
Anders RM :=)
Code sample 1 (EPAY.C):
static int CreateTransactionRecord(char *chTransactionType, const char
*szHost, const char *szBrandID)
{
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstTransactions = NULL;
// Define connection string.
_bstr_t strCnn("Provider=sqloledb;Data Source=sylvester;"
"Initial Catalog=testdb;User Id=******;Password=******;");
IADORecordBinding *picRs = NULL; // Interface Pointer declared
CTransactionRs transactions; // C++ Class object.
char szTimestamp[20]; //Buffer to hold timestamp
LogTrace(3, "DB-operasjon");
try
{
// Get current date and time
GetTimestamp(szTimestamp);
// Open a connection.
// This is where it all goes to ****
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
.....
.....
.....
} catch(_com_error &e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection);
PrintComError(e);
}
return ERR_SUCCESS;
}
Code sample 2 (EPAY.C):
/* *********************************
** PrintProviderError
** *********************************/
void PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
if( (pConnection->Errors->Count) > 0) // Here is where it chrashes
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("Error number: %x\t%s\n", pErr->Number,
(LPCSTR) pErr->Description);
}
}
}
Code sample 3 (COMIP.H):
// Allows this class to be used as the interface itself.
// Also provides simple error checking.
//
Interface* operator->() const throw(_com_error)
{
if (m_pInterface == NULL) {
_com_issue_error(E_POINTER);
}
return m_pInterface;
}
tbellavia@v...
$subst('Email.Unsub')
Message #3 by "Reed Mohn, Anders" <Anders.Reed.Mohn@i...> on Thu, 14 Jun 2001 15:37:04 +0200
|
|
*aaauuughhhh*
No, I didn't!
A copy/paste error from the sample I based my code on.
Works fine now.
I guess that's what I get for messing with stuff I
don't know the first thing about ... :=)
Thanks, Thomas!
Cheers,
Anders RM :)
> -----Original Message-----
> From: Thomas Bellavia [mailto:TBellavia@V...]
> Sent: 14. juni 2001 14:42
> To: ActiveX_Data_Objects
> Subject: [activex_data_objects] RE: Unhandled exeption?
>
>
> Did you first call :
> ::CoInitialize(NULL);
> before instantiating com components in your application?
>
>
|
|
 |