[mono-vb] Issue with callback/delegate

Klaus Siebke ksiebke at web.de
Sun Apr 26 12:59:29 EDT 2009


Hi,

I would like to use an external library in my Mono VB program. When using C#
I had no problems with the library, but with Mono VB I got some compiler
errors caused by a callback/delegate.
Below you can find the relevant lines of the (working) C# code and the same
coding in Mono VB syntax. I've also added the compiler errors.

----------------------------
Mono C# Code
----------------------------
/* error handler (callback function) */
public delegate void HPDF_ErrorHandler(uint error_no, uint detail_no,
        IntPtr user_data);
...
HPDF_ErrorHandler error_handler = new HPDF_ErrorHandler(HPdfDoc.ErrorProc);
...
public static void ErrorProc(uint error_no, uint detail_no,
     IntPtr user_data) {
     string s = "error-code=0x" + error_no.ToString("X") + " detail-code=" +
detail_no;
     throw new Exception(s);
}

----------------------------
Mono VB Code
----------------------------
' error handler (callback function) 
Public Delegate Sub HPDF_ErrorHandler(ByVal error_no As UInteger, _
                                      ByVal detail_no As UInteger, _
                                      ByVal user_data As IntPtr)
...
(Line 574)  Dim error_handler As New HPDF_ErrorHandler(HPdfDoc.ErrorProc)
...
Public Shared Sub ErrorProc(ByVal error_no As UInteger, ByVal detail_no As
UInteger, ByVal user_data As IntPtr)
    Dim s As String = ("error-code=0x" & error_no.ToString("X") & "
detail-code=") + detail_no
    Throw New Exception(s)
End Sub


----------------------
Compiler Errors:
----------------------
[Task:File=/share/source/mono/vbnet/vbharutest/vbharutest/hpdf.vb ,
Line=574, Column=65, Type=Error, Priority=Normal, Description=Argument not
specified for parameter 'user_data' of 'ErrorProc((System.UInt32,
System.UInt32, System.IntPtr))'.(VBNC30455)]
[Task:File=/share/source/mono/vbnet/vbharutest/vbharutest/hpdf.vb ,
Line=574, Column=65, Type=Error, Priority=Normal, Description=Argument not
specified for parameter 'detail_no' of 'ErrorProc((System.UInt32,
System.UInt32, System.IntPtr))'.(VBNC30455)]
[Task:File=/share/source/mono/vbnet/vbharutest/vbharutest/hpdf.vb ,
Line=574, Column=65, Type=Error, Priority=Normal, Description=Argument not
specified for parameter 'error_no' of 'ErrorProc((System.UInt32,
System.UInt32, System.IntPtr))'.(VBNC30455)]


When I use   

(Line 574)  Dim error_handler As new HPDF_ErrorHandler = AddressOf ErrorProc

instead, the compiler error would be:

[Task:File=/share/source/mono/vbnet/vbharutest/vbharutest/<MyGenerator> ,
Line=1, Column=1, Type=Error, Priority=Normal,
Description=CHANGEME(VBNC32008)]


Any ideas how to resolve this issue?

Thank you for your help,
Klaus
-- 
View this message in context: http://www.nabble.com/Issue-with-callback-delegate-tp23244124p23244124.html
Sent from the Mono - VB mailing list archive at Nabble.com.



More information about the Mono-vb mailing list