Connecting Tech Pros Worldwide Forums | Help | Site Map

Error While Accessing VB COM from PHP.

Newbie
 
Join Date: Feb 2009
Posts: 3
#1: Feb 5 '09
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

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Enum ApplicationErr
  4.     Unexpected = Error.Unexpected
  5. End Enum
  6.  
  7. Private Const m_csClassName As String = "XYZ.Application"
  8.  
  9. Public Sub Initialize(ByVal udl As String, ByVal log)
  10. On Error GoTo ErrInitialize
  11.     Dim enumErrorCode As xyzError
  12.     enumErrorCode = Success
  13.  
  14.     Dim oObjectContext As ObjectContext
  15.     Set oObjectContext = GetObjectContext()
  16.  
  17.     oObjectContext("Session")("ConString") = "FILE NAME=" & App.Path & "\" & udl
  18.     oObjectContext("Session")("ErrLog") = App.Path & "\" & log
  19.  
  20. ExitInitialize:
  21.     On Error Resume Next
  22.     Set oObjectContext = Nothing
  23.     If enumErrorCode <> Success Then
  24.         On Error GoTo 0
  25.         Call Err.Raise(enumErrorCode, m_csClassName, GetErrorDescription(enumErrorCode))
  26.     End If
  27.     Exit Sub
  28. ErrInitialize:
  29.     If Err.Source = m_csClassName Then
  30.         enumErrorCode = Err.Number
  31.     Else
  32.         enumErrorCode = Unexpected
  33.     End If
  34.     If Not (Err.Source = "XYZ.Application" And Err.Number = XYZ.ApplicationErr.Unexpected) Then Call LogError(m_csClassName & ".Initialize")
  35.     Resume ExitInitialize
  36. End Sub
  37.  
The PHP code used is :

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. try {
  4. $udl = new VARIANT("XYZ.udl",VT_BSTR);
  5. $errorlog = new VARIANT("ErrorLog.txt",VT_BSTR); 
  6.  
  7. $Q = new COM("XYZ.Application") or die("Cannot start XYZ");
  8. $lUserId = $Q->Initialize($udl,$errorlog);
  9.  
  10. echo $lUserId;
  11. catch (com_exception $e) 
  12. {
  13. $lUserId = array('errorCode' => $e->getCode(),
  14. 'errorMessage' => $e->getMessage(),
  15. 'errorFile' => $e->getFile(),
  16. 'errorLine' => $e->getLine());
  17. }
  18.  
  19. echo "<pre>";
  20. print_r($lUserId);
  21. echo "</pre>";
  22. ?>
  23.  
  24.  
It always generates an exception. Can someone please help me resolve this issue.

Also could it be a Type mismatch error?

thanks.

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#2: Feb 5 '09

re: Error While Accessing VB COM from PHP.


Does the error come as a PHP error or a VB error?
Newbie
 
Join Date: Feb 2009
Posts: 3
#3: Feb 6 '09

re: Error While Accessing VB COM from PHP.


the error comes as a VB error.
Newbie
 
Join Date: Feb 2009
Posts: 3
#4: Feb 6 '09

re: Error While Accessing VB COM from PHP.


Following is the exception generated :
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [errorCode] => -2147352567
  4.     [errorMessage] => Source: FQAI.Application
  5. Description: Unexpected error has occured
  6.     [errorFile] => D:\WWW\AIWM\website\aiwmtest\index1.php
  7.     [errorLine] => 7
  8. )
  9.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#5: Feb 6 '09

re: Error While Accessing VB COM from PHP.


Then it would make more sense to ask the question in our VB.NET forum.
Reply