Click here to Skip to main content
15,914,444 members
Home / Discussions / COM
   

COM

 
GeneralRe: passing char * to COM Object function Pin
Michael P Butler20-Sep-01 10:51
Michael P Butler20-Sep-01 10:51 
GeneralRe: passing char * to COM Object function Pin
Stephane Denis20-Sep-01 11:45
Stephane Denis20-Sep-01 11:45 
GeneralUser defined structure cannot be exported as a property Pin
19-Sep-01 7:52
suss19-Sep-01 7:52 
GeneralRe: User defined structure cannot be exported as a property Pin
ioannhs_s21-Sep-01 5:08
ioannhs_s21-Sep-01 5:08 
GeneralCOM Addins (A request for guidence and ideas) Pin
Michael P Butler18-Sep-01 23:34
Michael P Butler18-Sep-01 23:34 
GeneralRe: COM Addins (A request for guidence and ideas) Pin
Michael P Butler19-Sep-01 0:51
Michael P Butler19-Sep-01 0:51 
GeneralRe: COM Addins (A request for guidence and ideas) Pin
Anonymous27-Aug-02 9:06
Anonymous27-Aug-02 9:06 
QuestionProblem: VC client and COM+ Server Component, but VB client works just fine. Why? Pin
17-Sep-01 9:05
suss17-Sep-01 9:05 
I've been pulling my hair out this past two weeks in an attempt to find some kind of answer under this rug that rest so comfortably on my head.

The problem I'm having is setting my COM+ component as a server under the Component Service Manager. The component has a method that returns an ADO::_Connection pointer. My two test clients, written in VB an VC, take the returned _Connection pointer and perform a simple SQL store procedure call LOOP, which waits for 1 minute.

The VB client does just fine, probably taking care of all the marshalling in the background. Unfortunately, the VC client doesn't do the same. It throws a "NULL reference pointer pass to stub" exception when I try to execute the store procedure.

Below is the code to the component method call by the clients
STDMETHODIMP CSpeedLink::GetDBConnection(_Connection **ppSLDBConnection)
{
GetID(&m_bstrSpeedLinkID);
GetConnectionString(&m_slConnection);
// ASSERT: Retrieve SpeedLink id and connection string from the registry

if ((m_pConnectionPtr != NULL) && (m_pConnectionPtr->State == adStateOpen))
m_pConnectionPtr->Close();
// ASSERT: Closes any previously open connection

bool bConnected = FALSE;
while (!bConnected)
{
try
{
if (m_pConnectionPtr == NULL)
m_pConnectionPtr.CreateInstance(__uuidof(Connection));
// ASSERT: Instantiate connection if NULL

m_pConnectionPtr->Open(m_slConnection.ConnectionString,
TEXT(""), TEXT(""), adOpenUnspecified);
*ppSLDBConnection = m_pConnectionPtr.GetInterfacePtr();
bConnected = TRUE;
// ASSERT: Returns an opened db connection if successful.
}
catch (_com_error &error)
{
if (error.Error() == E_TIMEOUT)
{
error = NULL;
Sleep(5000);
// ASSERT: DB server busy try again in 5 seconds
}
else
{
error = NULL;
return E_FAIL;
// ASSERT: Error opening db connection
}
}
}
return S_OK;
}

The VB client code that calls the method above is as follow
Dim speedLink As New OALib.speedLink
Dim objConn As New ADODB.Connection
' ASSERT: Initialization

btnTestConnection.Enabled = False
Set objConn = speedLink.GetDBConnection
btnTestConnection.Enabled = True
' ASSERT: Connect to the SpeedLink database

If objConn.State = adStateOpen Then
objConn.CommandTimeout = 0;
objConn.Execute "exec loop", ,adCmdText
objConn.Close
MsgBox ("Successfully connected to SpeedLink database.")
' ASSERT: The connection was made successfully
Else
MsgBox ("Unable to connect to SpeedLink database.")
' ASSERT: Error - Unable to connect to the server
End If

Set objConn = Nothing
Set speedLink = Nothing

Similarly, the VC client code that calls the method is as follow
try
{
CoInitialize(NULL);

HRESULT hResult;
ISpeedLink FAR* pISpeedLink = (ISpeedLink FAR*)NULL;
_ConnectionPtr pConnection;

hResult = CoCreateInstance(CLSID_SpeedLink, NULL, CLSCTX_SERVER,
IID_ISpeedLink, (void FAR* FAR*)&pISpeedLink);
pConnection = pISpeedLink->GetDBConnection();

if (pConnection != NULL)
{
pConnection->CommandTimeout = 0;
pConnection->Execute("exec loop", NULL, adCmdText);
// ASSERT: Crashes at this line, when trying to execute procedure
pConnection->Close();
}

CoUninitialize();
}
catch (_com_error &error)
{
MessageBox(error.ErrorMessage(), "Error1", MB_OK);
}

MessageBox("Complete", "All Thread", MB_OK);

Note: A trace is placed on the SQL 2000 Server to verify the execution of the store procedure.

Note: The code
*ppSLDBConnection = m_pConnectionPtr.GetInterfacePtr();
was also replaced with
*ppSLDBConnection = m_pConnectionPtr.Detach();
both works flawlessly in VB but not in VC.

Now, down on my knee, I plea to any kind soul for a guiding hand and offer much needed help. Maybe, just maybe, I won't go bald after all.

Much thanks in advance for any help you can offer. Thank you.

Eek! | :eek: Cry | :(( Dead | X|
AnswerRe: Problem: VC client and COM+ Server Component, but VB client works just fine. Why? Pin
Carlos Antollini17-Sep-01 9:25
Carlos Antollini17-Sep-01 9:25 
GeneralRe: Problem: VC client and COM+ Server Component, but VB client works just fine. Why? Pin
17-Sep-01 9:39
suss17-Sep-01 9:39 
GeneralRPC Server Unavailable (Repost) Please help! Pin
Bill Wilson17-Sep-01 7:23
Bill Wilson17-Sep-01 7:23 
GeneralRPC Server Unavailable (Repost) Please help! Pin
Bill Wilson17-Sep-01 7:21
Bill Wilson17-Sep-01 7:21 
GeneralRe: RPC Server Unavailable (Repost) Please help! Pin
Bill Wilson17-Sep-01 7:25
Bill Wilson17-Sep-01 7:25 
GeneralRPC Server Unavailable from C++ client Pin
Bill Wilson14-Sep-01 14:11
Bill Wilson14-Sep-01 14:11 
GeneralRe: RPC Server Unavailable from C++ client Pin
Bill Wilson17-Sep-01 7:16
Bill Wilson17-Sep-01 7:16 
GeneralCOM SPY TOOL Pin
13-Sep-01 5:08
suss13-Sep-01 5:08 
GeneralAccelerators in WTL dialog Pin
Remon Spekreijse13-Sep-01 0:10
Remon Spekreijse13-Sep-01 0:10 
GeneralRe: Accelerators in WTL dialog Pin
Not Active17-Sep-01 7:48
mentorNot Active17-Sep-01 7:48 
GeneralRe: Accelerators in WTL dialog Pin
Remon Spekreijse17-Sep-01 21:13
Remon Spekreijse17-Sep-01 21:13 
GeneralCOM out of process server Pin
12-Sep-01 11:54
suss12-Sep-01 11:54 
GeneralRe: COM out of process server Pin
Ganesh Ramaswamy12-Sep-01 13:16
Ganesh Ramaswamy12-Sep-01 13:16 
GeneralRe: COM out of process server Pin
12-Sep-01 16:24
suss12-Sep-01 16:24 
GeneralIShellLink Pin
mrlister11-Sep-01 6:28
mrlister11-Sep-01 6:28 
Generalop= and copy ctor with COM pointers Pin
10-Sep-01 12:45
suss10-Sep-01 12:45 
GeneralRe: op= and copy ctor with COM pointers Pin
Michael Dunn10-Sep-01 15:22
sitebuilderMichael Dunn10-Sep-01 15:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.