tag:blogger.com,1999:blog-21773982.post3002330173033655244..comments2023-11-08T03:20:51.357-08:00Comments on xTechNotes - Technical Computing Programming Notes: Callback to C# from Unmanaged FortranUnknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-21773982.post-20961289277759045502011-01-11T17:53:46.054-08:002011-01-11T17:53:46.054-08:00Hi Kensun87,
I have solved the problem of passing...Hi Kensun87,<br /><br />I have solved the problem of passing arrays in callbacks, in the article:<br /><br />Callback to C# from Unmanaged Fortran - PASSING ARRAYS<br /><br />http://xtechnotes.blogspot.com/2011/01/callback-to-c-from-unmanaged-fortran.htmlElkanahhttps://www.blogger.com/profile/12387309223172492997noreply@blogger.comtag:blogger.com,1999:blog-21773982.post-14335638335988043492010-11-27T22:28:11.035-08:002010-11-27T22:28:11.035-08:00Hi
I have been trying to pass an integer array thr...Hi<br />I have been trying to pass an integer array through the callback and I also got the first element only. Could not figure out how to get the full array. After some googling, I believe the solution to this lies in using IntPtr. I tried a bit using IntPtr but still can get it to work (given that I have very little knowledge in using IntPtr). I have attached some links below which perhaps could give you some ideas of what to try. If you are successful, please post your solution in this blog as I'm sure many others would like to know too. Please feel free to investigate more with IntPtr.<br /><br />http://www.pcreview.co.uk/forums/thread-2510031.php<br />http://msdn.microsoft.com/en-us/library/0t7xwf59.aspxElkanahhttps://www.blogger.com/profile/12387309223172492997noreply@blogger.comtag:blogger.com,1999:blog-21773982.post-25924132816822980012010-11-24T06:46:06.313-08:002010-11-24T06:46:06.313-08:00I've managed to get the array reference passed...I've managed to get the array reference passed back to C#, but it always has length 1. I can't seem to find a way to get C# to remember the length of the array when it's passed from Fortran to C#.kensun87https://www.blogger.com/profile/09201430883370748541noreply@blogger.comtag:blogger.com,1999:blog-21773982.post-75624131737144000082010-11-24T03:56:02.825-08:002010-11-24T03:56:02.825-08:00I have not tried using an array as an argument, bu...I have not tried using an array as an argument, but I imagine it would be similar to the integer in the example. Try using a 1D array first.<br /><br />Key changes to be made to the Fortran are the lines:<br />call progressCllBak(iCB)<br /><br /><br />Key changes to be made to the C# are the lines:<br />public delegate void dgateInt(ref int numYears);<br /><br />public void onUpdateProgress(ref int progCount)<br /><br /><br />Of course there are details of the array itself which I have not included here. It may take some trial and error. If you manage to be successful, feel free to put your solution here.Elkanahhttps://www.blogger.com/profile/12387309223172492997noreply@blogger.comtag:blogger.com,1999:blog-21773982.post-74009312293080480552010-11-23T12:42:38.788-08:002010-11-23T12:42:38.788-08:00This seems to work perfectly for callbacks that ta...This seems to work perfectly for callbacks that take simple numbers as arguments (the progress, in your example). However, how would you modify your code to send both the array and progress value back to C#?<br /><br />For example, if your fortran looked like this:<br /><br />call progressCllBak(iArr, iCB)<br /><br />Any help would be appreciated.kensun87https://www.blogger.com/profile/09201430883370748541noreply@blogger.com