- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Im work on an application where currently everything is done in Visual Basic. We are now placing all the calculations in a Fortran Dll. In Visual Basic we update a progress bar at certain points to indicate how much of the calculation is done.
Im just wondering what is the best way to do this from Fortran. I know that you can use a 'Callback' from Fortran but I have heard this can cause problems and use alot of memory.
What about if I sent a flag variable (say an integer) to the Dll routine Im calling and then increase the value at different stages. Then in Visual Basic using a timer check the value of this variable once every second or half second.
Would this cause a problem when both VB and CVF are accessing the same variable (memory space) at the same time ?
Im just wondering what is the best way to do this from Fortran. I know that you can use a 'Callback' from Fortran but I have heard this can cause problems and use alot of memory.
What about if I sent a flag variable (say an integer) to the Dll routine Im calling and then increase the value at different stages. Then in Visual Basic using a timer check the value of this variable once every second or half second.
Would this cause a problem when both VB and CVF are accessing the same variable (memory space) at the same time ?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have searched a lot, but still don't know how to use callbacks. If anyone knows, please, write down a simple example with a full code in BOTH VF and VB.
I don't know how you want to check the flag by basic while running the fortran dll code?
The only way I was able to solve this (without callbacks) was to make a few do loops in basic code and a few corresponding NAMED do loops in fortran code. I also placed some IF statements with EXIT and CYCLE in fortran code.
That allows me to call fortran code for each generation and each iteration and meanwhile visual basic refreshes the simulation control panel. In my case it is approx. every 2 seconds. It works fine, but I don't know if you can apply this to your problem.
You can get access violation if you pass say an input value to dll and modify the same memory location in that dll. So I use extra arrays to pass input and extra for output.
I don't know how you want to check the flag by basic while running the fortran dll code?
The only way I was able to solve this (without callbacks) was to make a few do loops in basic code and a few corresponding NAMED do loops in fortran code. I also placed some IF statements with EXIT and CYCLE in fortran code.
That allows me to call fortran code for each generation and each iteration and meanwhile visual basic refreshes the simulation control panel. In my case it is approx. every 2 seconds. It works fine, but I don't know if you can apply this to your problem.
You can get access violation if you pass say an input value to dll and modify the same memory location in that dll. So I use extra arrays to pass input and extra for output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't know why a callback would cause any particular problems. A callback is just a routine that is called by the API routine to denote certain events performed by the API routine. Here is a very simple example in Fortran only, but the concept is the same.
James
program callback_example external callee call APIroutine (LOC(callee)) end subroutine callee print *, 'callee' return end subroutine APIroutine (userproc) use dfwinty integer(HANDLE) userproc interface subroutine user_defined_routine end subroutine end interface pointer (fptr, user_defined_routine) integer i fptr = userproc do i = 1, 5 call user_defined_routine end do return endThe callback routine is "callee" and you need to pass its location to your Fortran routine. Define the appropriate interface for your callback routine and you have a callback. Add any desired error checking.
James

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page