Haho2
asked on
works in VB, doesn in ASP...
hi, I have a interesting problem here.
I created a VC6 COM object for use in VB and ASP. It works fine in VB but crashes the IIS4 when called from ASP.
What is the differences (memory allocation, etc) between VB and ASP that could cause this difference in general?
Any suggestions/ideas?
Thanks
PS. My server is installed clean,
so it is not a corrupted server.
I created a VC6 COM object for use in VB and ASP. It works fine in VB but crashes the IIS4 when called from ASP.
What is the differences (memory allocation, etc) between VB and ASP that could cause this difference in general?
Any suggestions/ideas?
Thanks
PS. My server is installed clean,
so it is not a corrupted server.
Does the COM get any parameters from the ASP ?
It can be conversion error after all ASP use Varient type and not
Integer,Long ,String....
It can be conversion error after all ASP use Varient type and not
Integer,Long ,String....
ASKER
here is a basic code of a COM interface in VC6:
AnsiToUni and UniToAnsi are both workable functions.
does it look ok?
STDMETHODIMP CMyCOM::GetResultFunction (BSTR szTxnID, VARIANT *pvarAuthResult)
{
AFX_MANAGE_STATE(AfxGetSta ticModuleS tate())
// TODO: Add your implementation code here
int iAuthResultLen = 0,
ierr = 0;
char *pszTxnID = NULL,
*pszAuthResult = NULL;
BSTR szAuthResult = NULL;
VARIANT varAuthResult;
UniToAnsi ( szTxnID, &pszTxnID );
GetAuthorizationResultLeng th ( pszTxnID, &iAuthResultLen );
pszAuthResult = (char *) LocalAlloc ( LMEM_ZEROINIT, sizeof(char) * (iAuthResultLen + 1) );
if ( !pszAuthResult )
return E_OUTOFMEMORY;
ierr = CLibraryFunction( pszTxnID, pszAuthResult );
AnsiToUni ( pszAuthResult, &szAuthResult );
VariantInit ( &varAuthResult );
varAuthResult.vt = VT_BSTR;
varAuthResult.bstrVal = SysAllocString ( szAuthResult );
*pvarAuthResult = varAuthResult;
if ( pszTxnID ) LocalFree ( pszTxnID );
if ( pszAuthResult ) LocalFree ( pszAuthResult );
if ( szAuthResult ) LocalFree ( szAuthResult );
return S_OK;
}
AnsiToUni and UniToAnsi are both workable functions.
does it look ok?
STDMETHODIMP CMyCOM::GetResultFunction (BSTR szTxnID, VARIANT *pvarAuthResult)
{
AFX_MANAGE_STATE(AfxGetSta
// TODO: Add your implementation code here
int iAuthResultLen = 0,
ierr = 0;
char *pszTxnID = NULL,
*pszAuthResult = NULL;
BSTR szAuthResult = NULL;
VARIANT varAuthResult;
UniToAnsi ( szTxnID, &pszTxnID );
GetAuthorizationResultLeng
pszAuthResult = (char *) LocalAlloc ( LMEM_ZEROINIT, sizeof(char) * (iAuthResultLen + 1) );
if ( !pszAuthResult )
return E_OUTOFMEMORY;
ierr = CLibraryFunction( pszTxnID, pszAuthResult );
AnsiToUni ( pszAuthResult, &szAuthResult );
VariantInit ( &varAuthResult );
varAuthResult.vt = VT_BSTR;
varAuthResult.bstrVal = SysAllocString ( szAuthResult );
*pvarAuthResult = varAuthResult;
if ( pszTxnID ) LocalFree ( pszTxnID );
if ( pszAuthResult ) LocalFree ( pszAuthResult );
if ( szAuthResult ) LocalFree ( szAuthResult );
return S_OK;
}
Yes I see the problem right there in the first line -- the function header itself.
ASP supports only two datatypes -- Variant and ADOR Recordsets. Hence whenever coding for ASP, all parameters to functions/procedures must be of either of these two datatypes.
BSTR won't work. What you can do is to typecast parameters into the correct type INSIDE the function.
Hope that helps.
ASP supports only two datatypes -- Variant and ADOR Recordsets. Hence whenever coding for ASP, all parameters to functions/procedures must be of either of these two datatypes.
BSTR won't work. What you can do is to typecast parameters into the correct type INSIDE the function.
Hope that helps.
ASKER
like this??
sorry cause I am not familiar with COM programming.
STDMETHODIMP CMyCOM::GetResultFunction (VARIANT szTxnID, VARIANT *pvarAuthResult)
{
BSTR bstrTxnID = NULL;
/* given that I know what field to access, in this case: bstrval */
bstrTxnID = szTxnID.bstrVal;
........
}
increasing points
sorry cause I am not familiar with COM programming.
STDMETHODIMP CMyCOM::GetResultFunction (VARIANT szTxnID, VARIANT *pvarAuthResult)
{
BSTR bstrTxnID = NULL;
/* given that I know what field to access, in this case: bstrval */
bstrTxnID = szTxnID.bstrVal;
........
}
increasing points
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In addition it's I it's recommended to convert all the variables to Variant just for any case .
ASKER
good point , but Vin32 clearly deserves the points for pointing out the problem out for me! :)
Thanks Haho2.
Give the few lines of code or the method which fails.. then can help