Link to home
Start Free TrialLog in
Avatar of Haho2
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.

Avatar of halapaya
halapaya

I think you should post some code part.. there can be lot of reasons.. i mean we are working with computers.

Give the few lines of code or the method which fails.. then can help
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....
Avatar of Haho2

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(AfxGetStaticModuleState())

      // TODO: Add your implementation code here
      int                  iAuthResultLen = 0,
      ierr = 0;
      char            *pszTxnID = NULL,
                        *pszAuthResult = NULL;
      BSTR            szAuthResult = NULL;
      VARIANT            varAuthResult;

      UniToAnsi ( szTxnID, &pszTxnID );

      GetAuthorizationResultLength ( 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;
}
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.

Avatar of Haho2

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
ASKER CERTIFIED SOLUTION
Avatar of Vin32
Vin32

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
In addition it's I it's recommended to convert all the variables to Variant just for any case .
Avatar of Haho2

ASKER

good point , but Vin32 clearly deserves the points for pointing out the problem out for me! :)
Thanks Haho2.