Hi, Is there a way to return messages from my Active X DLL to my ASP application. I know msgbox dont work, I am looking for something similar!
Printable View
Hi, Is there a way to return messages from my Active X DLL to my ASP application. I know msgbox dont work, I am looking for something similar!
Can you be more specific as to what you want to do ?
Where you want to store the returned messages ?
Session, Application or page level ?
You can get classes to raise events, and you can pass parameters to the events....
Declare the event at the top of the class like this:
Then, anywhere in the class code, you can raise the event by using this syntaxCode:Public Event Boo(ByVal Argh As String)
Next when you are using your ActiveX DLL, you must declare the object to include the events, like this:Code:RaiseEvent Boo ("Woooooo")
Then you simply declare the event sub as you do all other event subs -Code:Dim WithEvents ClassObject As MyAxDLL.clsObject
Hope that helps... :DCode:Private Sub ClassObject_Boo(ByVal Argh As String)
MsgBox Argh
End Sub
Thanks for the reply! I was looking at callbacks but it looks to complicated, I think the "events" will work great!:D
How Do I raise the event in my ASP page?
I cant declare using "Withevents"!
You could always raise custom errors, though. At the very least, return a status from your methods that you could use.VB Code:
Public Function MyMethod( _ ByVal MyParam As Integer, _ Optional ByRef ErrRetVal As Long, _ Optional ByRef ErrRetSrc As String, _ Optional ByRef ErrRetDesc As String) On Error Goto err_MyMethod 'If It's Something You don't like... If MyParam = 17 Then 'Raise an Error (arbitrary number) Err.Raise vbObjectError + 8080, , "I don't like this number" End If exit_MyMethod: 'Do cleanup if necessary Exit Function err_MyMethod: ErrRetVal = Err.Number ErrRetSrc = Err.Source ErrRetDesc = Err.Description Resume exit_MyMethod End Function
Code:Dim objX, vntX, vntNum, vntSrc, vntDesc
Set objX = Server.CreateObject("MyDLL.clsMyClass")
vntX = 17
Call objX.MyMethod(vntX, vntNum, vntSrc, vntDesc)
If vntNum <> 0 Then 'Returned an error
If vntNum = vbObjectError + 8080 Then 'Our Custom Error
Response.Write "We Don't Like this parameter!!"
Response.End
Else
Response.Write "An Error Has occurred<br>" & vbCrLf
Response.Write "Error Number: " & vntNum & "<br>" & vbCrLf
Response.Write "Error Souce: " & vntSrc & "<br>" & vbCrLf
Response.Write "Error Description: " & vntDesc & "<br>" & vbCrLf
Response.End
End If
End If
'Continue as if success :)
WALDO .. i couldnt get clear abt ur last example .. till Raising ERR i got but how to handle these err in ASP ..
well i have too similar kind of problem .. I am simply raising an event from DLL and i m using Object Tag of DLL in my ASP page ..
my properties / methods are working fine but i m not able catch DLL 's event as i cant use withevents ... can you please tell me more specificly abt ur example of Raise Err....
I would really appretiate ...
That's right, you can't catch events from ASP.
In my example, the method in the DLL catches errors and handles them by pushing them out to the three variant parameters (vntNum, vntSrc, vntDesc). These 3 params are representative of any error that occured in the DLL.
In ASP, you test for the value of vntNum returned from the DLL method. If it is not 0, then you have raised an error from your DLL and vntSrc and vntDesc should have values as well.