Active X, Again; Sorry Jose

Started by Brad Warmuskerken, October 21, 2004, 01:22:22 PM

Previous topic - Next topic

Brad Warmuskerken

Alright, I've almost got this, except for one thing.

I'm trying to intiate a Web Server ActiveX control from OcrtoGroup.  I've been able to get the control up and running with prior help from Jose.

Now comes the second part of this.  To enable the PHP portion of the server, I need to load the ISAPI extension.  There are 2 seperare ActiveX DLLs that need to be initiated for this to work.

In VB, I create a reference to both the WebSvr TLIB and Server Extension TLIB.

Here's the VB code:

       'Setup the server extension
       Set m_ext = New OctoSvrExtension.ISAPIExt
       res = m_ext.SetExtensionDLL(txtPHPLoc)
       If res <> 0 Then
           sBuf = String$(1024, 0)
           res = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_IGNORE_INSERTS, ByVal 0&, res, 0, sBuf, 1024, 0)
           sBuf = Left$(sBuf, res)
           MsgBox "Unable to load extension DLL" & vbCrLf & sBuf, vbCritical
           Exit Sub
       End If

   Set m_svr = New WebSvrASP.Server
   res = InStrRev(txtDefDoc, "\")
   
   m_svr.DefaultDirectory = Left$(txtDefDoc, res - 1)
   m_svr.DefaultDocument = Mid$(txtDefDoc, res + 1)
   m_svr.Port = txtPort
   
   If cbLog And txtLog <> "" Then
       res = InStrRev(txtLog, "\")
       m_svr.LogPath = Left$(txtLog, res - 1)
       m_svr.LogLevel = 2
       m_ext.LogEnable = True
   Else
       m_svr.LogLevel = 0
   End If
   
 
   res = m_svr.StartServer()
   If res = 0 Then
       MsgBox "Unable to start server" & vbCrLf & m_svr.LastError, vbCritical
       Exit Sub
   End If


Here's what I've tried in FF/PB.  The server runs, but the PHP portion of the server doesn't work.  Otherwise, it serves HTM and ASP files fine.

Dim vVar As Variant                                    
Dim vVar2 As Variant
Dim vSer As Variant
Dim sErrorMsg As String

vVar = CurDir$ & "\php4isapi.dll"
Object Call DISPATCH_FORM1_OCXCONTROL1.SetExtensionDLL(vVar) To vVar2
If Variant#(vVar2) <> 0 Then
MsgBox "Error with extensions"
End If
                               
vVar = "C:\wsvr"                
Object Let DISPATCH_FORM1_OCXCONTROL2.DefaultDirectory = vVar
vVar = 80
Object Let DISPATCH_FORM1_OCXCONTROL2.Port = vVar  
vVar = "index.htm"
Object Let DISPATCH_FORM1_OCXCONTROL2.DefaultDocument = vVar  
  Object Call DISPATCH_FORM1_OCXCONTROL2.StartServer() To vVar2

If Variant#(vVar) = 0 Then
Object Call DISPATCH_FORM1_OCXCONTROL2.LastError To vVar
sErroMsg = Variant$(vVar)
MsgBox sErroMsg
End If  

Jose Roca

If Variant#(vVar) = 0 Then  ???

It should be vVar2.

The last assignment to vVar in your code is vVar = "index.htm" and Variant#(vVar) will return always 0, since it contains an string.

Brad Warmuskerken

You're right, but again, that was my typo in the post, as is sErroMsg instead of sErrorMsg.  This (corrected) code runs fine.  The WebServer starts and serves web pages.  The problem lies in that I it doesn't seem to be seeing the extension that I load prior to starting the server.


Dim vVar As Variant                                    
Dim vVar2 As Variant
Dim sErrorMsg As String

vVar = CurDir$ & "\php4isapi.dll"
Object Call DISPATCH_FORM1_OCXCONTROL1.SetExtensionDLL(vVar) To vVar2
If Variant#(vVar2) <> 0 Then
MsgBox "Error with extensions"
End If
                               
vVar = "C:\wsvr"                
Object Let DISPATCH_FORM1_OCXCONTROL2.DefaultDirectory = vVar
vVar = 80
Object Let DISPATCH_FORM1_OCXCONTROL2.Port = vVar  
vVar = "index.htm"
Object Let DISPATCH_FORM1_OCXCONTROL2.DefaultDocument = vVar  
 
  Object Call DISPATCH_FORM1_OCXCONTROL2.StartServer() To vVar2

If Variant#(vVar2) = 0 Then
Object Call DISPATCH_FORM1_OCXCONTROL2.LastError To vVar
sErrorMsg = Variant$(vVar)
MsgBox sErrorMsg
End If  
End Function

Jose Roca

And CurDir$ & "\php4isapi.dll"  is the correct path?

Check the error returned as you do in the VB code. You can use:

FUNCTION WinErrorMessage (BYVAL dwError AS DWORD) AS STRING

  LOCAL pBuffer AS ASCIIZ PTR, ncbBuffer AS DWORD, Txt AS STRING

  IF dwError = 0 THEN EXIT FUNCTION
  ncbBuffer = FormatMessage(%FORMAT_MESSAGE_ALLOCATE_BUFFER OR _
     %FORMAT_MESSAGE_FROM_SYSTEM OR %FORMAT_MESSAGE_IGNORE_INSERTS, _
     BYVAL %NULL, dwError, BYVAL MAKELANGID(%LANG_NEUTRAL, %SUBLANG_DEFAULT), _
     BYVAL VARPTR(pBuffer), 0, BYVAL %NULL)
  IF ncbBuffer THEN
     Txt = Txt & FORMAT$(dwError) & " [&H" & HEX$(dwError, 8) & "] " & @pBuffer
     LocalFree pBuffer
  END IF

  FUNCTION = Txt

END FUNCTION

If Variant#(vVar2) <> 0 Then
   MsgBox WinErrorMessage(Variant#(vVar2))
End If

Brad Warmuskerken

I added the code, but the Extension appears to load correctly as the variants value is 0.  If I change the name of the dll, it of course does error as expected.  

I'm not sure where to go from here.  Everything seems to be working, but the PHP extension doesn't seem to be loaded since it will not run the PHP scripts.

Could it be something in the bindings?  Early/Late?  I'm grabbing here.

Jose Roca

The differences between early binding and late binding is that early binding checks your syntax at compile time and does the calls a bit faster, so this is not the problem.

Sorry, but I can't investigate since I don't have this component installed in my computer.

Brad Warmuskerken

Jose,  thanks for all the help.  I really appreciate the time you've taken.  It's been a big help getting me started in using FF and ActiveX.  I'll continue work on this and see where it gets me.

Thanks,
Brad

Brad Warmuskerken

Alright, I'm getting closer.

I've run into another little problem that is holding me up.

In the include file for the activex component, there is a function


' ********************************************************************************************
' Function name: PageRequested
' ********************************************************************************************
Function WebSvrASPDServer_events2_PageRequested(ByVal dwCookie As Dword, ByRef pdispparams As DISPPARAMS) As Dword
  Local pv As Variant Ptr, pvapi As VARIANTAPITYPE Ptr
  pv = pdispparams.VariantArgs : pvapi = pv
'  ==============================================================================
'  Parameters in DISPPARAMS are zero based and in reverse order
'  ==============================================================================
  Local RequestObject As Long
  RequestObject = Variant#(@pv[1])
  Local ResponseObject As Long
  ResponseObject = Variant#(@pv[0])      

'  ==============================================================================
'  *** Put your code here ***
'  ==============================================================================
  Function = 0  ' %S_OK
End Function



This  appears correct, but in VB, the Parameters are WebSvrASP.IRequest and WebSvrASP.IResponse.  How do I get the longs in the PB Function to be these Objects?  

If I try:

Dim vVar as Variant

Object Get RequestObject.DefaultResponseFile To vVar


I get an Error 533; Dispatch Object Variable Expected.

Jose Roca

PB can't convert long or dword pointers to objects. You can do it with the help of the procedure TB_MakeDispatchVariant, contained in the file FF_COM32.INC, already included in your project.


Dim vRequest As Variant
Dim oRequest As Dispatch
Dim vVar As Variant

' Make a dispatch variant with the pointer contained in RequestObject
TB_MakeDispatchVariant  RequestObject, vRequest
Set oRequest = vRequest
If IsTrue IsObject(oRequest) Then
  Object Get oRequest.DefaultResponseFile To vVar
  Set oRequest = Nothing
End If

Brad Warmuskerken

You amaze me.  Thank you, yet again.

Now that I'm on that road.  I then have to make a call to a method in an the activeX control.   I get a compilation error for invalid variable type in the CALL statement


Dim sPage As String
Dim vRequest As Variant
Dim oRequest As Dispatch
Dim vVar As Variant
Dim vResponse As Variant
Dim oResponse As Dispatch

' Make a dispatch variant with the pointer contained in RequestObject
TB_MakeDispatchVariant  RequestObject, vRequest
TB_MakeDispatchVariant  ResponseObject, vResponse

Set oRequest = vRequest                          
Set oResponse = vResponse

If IsTrue IsObject(oRequest) Then
  Object Get oRequest.DefaultResponseFile To vVar

End If
sPage = Variant$(vVar)

   If Right$(sPage, 4) = ".PHP" Or Right$(sPage, 5) = ".PHP3" Then
Object Call DISPATCH_FORM1_OCXCONTROL1.ProcessRequest(DISPATCH_FORM1_OCXCONTROL2, vRequest, vResponse) To vVar
Set oRequest = Nothing    
Set oResponse = Nothing
           Exit Function

   End If
Set oRequest = Nothing    
Set oResponse = Nothing

Jose Roca

PB can't currently pass object variables as parameters (this is in the wish list), but you can assign it to a variant and use this variant instead.


Dim vObj As Variant
Set vObj = DISPATCH_FORM1_OCXCONTROL2

Object Call DISPATCH_FORM1_OCXCONTROL1.ProcessRequest(vObj, vRequest, vResponse) To vVar

Brad Warmuskerken

Geez, I tried...

Dim vObj as Variant
vObj = DISPATCH_FORM1_OCXCONTROL1

But that didn't work.  Never thought to use: Set

It is working now, with your help, I've been able to get this control to work and process both ASP, and PHP.

Jose, do you have a PayPal account?  You've been a great help.
you can contact me at:

MyFirstName@MyLastName.com

replace the name's above with mine.

Thanks again,
Brad

Jose Roca

I'm glad that all is working fine now. No money, please. Being able to be helpful is enough reward.

Brad Warmuskerken

you're very kind.  Thank you!

gian young

:)

As an outside observer to the dialog on this topic I can only express my amazement and respect to Jose for his knowledge and his willingness to assist other users.

I am also struggling to learn and succeed in getting an Active X control working with FireFly, I may get there without calling for help (I hope). The examples and solutions that I can read here have helped in my own understanding of how to use FireFly with Active X's.

Thank you Jose.

P.S. I would willingly pay for a handbook by Jose on how to implement Active X controls with FireFly with example code should he consider producing such.

Regards

Gian Young

Dataman Barcode Systems Australia