Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Callback help

Status
Not open for further replies.

Guern

Programmer
Jun 22, 2001
91
GB
hello,

I need some help getting a callback from a com object written in c+ to work

All I get now is 'The specified cast is not valid'. My code is

Imports System.Runtime.InteropServices


Module Module1

Public Delegate Function CallBackDelegate(ByVal e As Long, ByVal param As Integer, ByVal objectName As IntPtr, ByVal testName As IntPtr, ByVal objectID As Long)

' below if the function as is appears in C
'CALLBACK_RESULT clbk_fn (unsigned long Event,
' unsigned int Param,
' const char *ObjectName,
' const char *VirusName,
' unsigned long ObjectID)

Sub Main()
Dim VirusScanner As New IKAVELib.KAVE

Try
VirusScanner.InitializeW(vbNull, vbNull, New CallBackDelegate(AddressOf CallBackHandler))
Catch
Debug.WriteLine(Err.Description)
Finally
VirusScanner = Nothing
End Try
End Sub

Private Function CallBackHandler(ByVal e As Long, ByVal param As Integer, ByVal objectName As IntPtr, ByVal testName As IntPtr, ByVal objectID As Long)
' Private Function CallBackHandler(ByVal e As UInt32, ByVal param As UInt16, ByVal objectName As String, ByVal testName As String, ByVal objectID As UInt32) As IKAVELib.KAVE
'ByVal e As Long, ByVal param As Integer, ByVal objectName As IntPtr, ByVal testName As intptr, ByVal objectID As lon
Console.WriteLine("got here")
End Function

End Module


I've changed the function variable types to see if it made any difference. They were as per the c example previously with UInt's etc.

The software always fails at the initialise function. The dll is referenced and properly registered on the system.

If anyone has any suggestions, that'd be great :)

Thanks.
 
Have you tried using an int32 or int16 as your first argument?

My guess is that it is the unsigned int that is killing you.

However just a guess. api calls are a pain.

 
Hi,

Thanks, but yes. I actually started with them.
 
have you tried:
Code:
VirusScanner.InitializeW(0, 0, New CallBackDelegate(AddressOf CallBackHandler))

or

Code:
VirusScanner.InitializeW(dbnull.value, dbnull.value, New CallBackDelegate(AddressOf CallBackHandler))

Also, your CallBackHandler function isn't returning anything, so that could be an issue.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hi,

Thanks. Tried both of those. Same error.

I tried

Public Delegate Function CallBackDelegate(ByVal e As Long, ByVal param As Integer, ByVal objectName As IntPtr, ByVal testName As IntPtr, ByVal objectID As Long) as Ikav.kave

I still get the same 'Specified cast is not valid.' error.

I'd really love to get this working, so any other suggestions would be most welcome.
 
What about the return type?

This line is throwing the exception, right?
Code:
 VirusScanner.InitializeW(vbNull, vbNull, New CallBackDelegate(AddressOf CallBackHandler))

what is it expecting for it's parameters?

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Yes, with 'Specified cast is not valid.'

A path name (temp folder), A path name(to databases), Callback function

The first 2 can accept NULL as the parameter and the function will use it's built in defaults.

The return type is 'Ikavlib.Kave' according to vb.net. BTW - there is a typo in the above code. I put ikav.kave, I have actually used Ikavlib.kave'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top