amey72 0 Newbie Poster

Hi,

I am trying to connect to a COM component using PHP, but keep on recieving an "Unexpected error has occured" message.

The COM component code is

Option Explicit

Public Enum ApplicationErr
    Unexpected = Error.Unexpected
End Enum

Private Const m_csClassName As String = "XYZ.Application"

Public Sub Initialize(ByVal udl As String, ByVal log)
On Error GoTo ErrInitialize
    Dim enumErrorCode As xyzError
    enumErrorCode = Success
    
    Dim oObjectContext As ObjectContext
    Set oObjectContext = GetObjectContext()
    
    oObjectContext("Session")("ConString") = "FILE NAME=" & App.Path & "\" & udl
    oObjectContext("Session")("ErrLog") = App.Path & "\" & log
    
ExitInitialize:
    On Error Resume Next
    Set oObjectContext = Nothing
    If enumErrorCode <> Success Then
        On Error GoTo 0
        Call Err.Raise(enumErrorCode, m_csClassName, GetErrorDescription(enumErrorCode))
    End If
    Exit Sub
ErrInitialize:
    If Err.Source = m_csClassName Then
        enumErrorCode = Err.Number
    Else
        enumErrorCode = Unexpected
    End If
    If Not (Err.Source = "XYZ.Application" And Err.Number = XYZ.ApplicationErr.Unexpected) Then Call LogError(m_csClassName & ".Initialize")
    Resume ExitInitialize
End Sub

The PHP code used is :

<?php

try {
$udl = new VARIANT("XYZ.udl",VT_BSTR);
$errorlog = new VARIANT("ErrorLog.txt",VT_BSTR); 

$Q = new COM("XYZ.Application") or die("Cannot start XYZ");
$lUserId = $Q->Initialize($udl,$errorlog);

echo $lUserId;
} 
catch (com_exception $e) 
{
$lUserId = array('errorCode' => $e->getCode(),
'errorMessage' => $e->getMessage(),
'errorFile' => $e->getFile(),
'errorLine' => $e->getLine());
}

echo "<pre>";
print_r($lUserId);
echo "</pre>";
?>

It always generates an exception. Can someone please help me resolve this issue.

Also could it be a Type mismatch error?

thanks.