xsharp.eu • XS1030 #warning: 'Callback function modified to use a DELEGATE by xPorter.
Page 1 of 1

XS1030 #warning: 'Callback function modified to use a DELEGATE by xPorter.

Posted: Mon Mar 02, 2020 11:13 pm
by ic2
Another new thing although searching on it the warning seems to be present since 2017...but I can't remember seeing it earlier... This is not my code, but the ACF-Shell Window to allow gradient fills, background text etc.

Original code
// Subclass our MDI Client
hClient := SELF:Handle( 4 )
SetWindowLong( hClient, GWL_WNDPROC, LONG( _CAST, @ACF_MdiClientWinProc() ) )

XS1030 #warning: 'Callback function modified to use a DELEGATE by xPorter. Please review:

xPorter result

hClient := SELF:Handle( 4 )
#warning Callback function modified to use a DELEGATE by xPorter. Please review.
// SetWindowLong( hClient, GWL_WNDPROC, LONG( _CAST, @ACF_MdiClientWinProc() ) )
STATIC LOCAL oACF_MdiClientWinProcDelegate := ACF_MdiClientWinProc AS ACF_MdiClientWinProc_Delegate
SetWindowLong( hClient, GWL_WNDPROC, LONG( _CAST, System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(oACF_MdiClientWinProcDelegate) ) )

Wolfgang explained in https://www.xsharp.eu/forum/german/1668 ... ssen#12283 more about delegates but frankly I have no idea if the generated code could work.

In a final real life conversion I would most likely prefer to search a better solution than using old code I didn't write and which seems to 'break in' into all kind of default VO/Windows behavior. Chances are that this ain't going to work anyway. But for now I would like to understand what this is supposed to do. There are a few more, like GetWindow, SubClassWindow

DIck

XS1030 #warning: 'Callback function modified to use a DELEGATE by xPorter.

Posted: Tue Mar 03, 2020 12:36 am
by Chris
Hi Dick,

The original code uses a pointer to a function and passes it to a Win32 function (SetWindowLong()). This is not allowed in .Net, because that pointer can actually point to anything (by user mistake) and it is not possible to make sure it is safe to use it. Instead of that, .Net uses DELEGATEs, which are also pointers to functions/methods, but they fully describe the function and are safe to be used/passed to Win32 calls.

The VOXporter automatically creates the necessary syntax for using the delegate instead of a function pointer, it just gives you a warning/information that it did that, so you can review what it did. Normally you do not need to worry about this, it does write the correct code and you do not need to deal with it. That is, until for some reason indeed it does not work correctly at runtime :). In case this happens, please let us know, so we can investigate this.

XS1030 #warning: 'Callback function modified to use a DELEGATE by xPorter.

Posted: Tue Mar 03, 2020 11:37 am
by ic2
Thanks for the explanation.

I will remove the comment and see if it works. That may take a while as it is only one of my (support) libraries I converted. But it's a large one and if it compiles error free we are closer to X# instead of VO than ever

Dick