- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm calling a DLL from Visual Basic. It works now well (due to your valuable help). I'm passing all my variables in arrays, each array for a certain variable type.
The code in VB is written so that in each loop, arrays are refilled with new values and program calls DLL. DLL then runs number of simulation iterations (within a single call) and sends results back to VB in arrays. New arrays are refilled and so on until all simulation scenarios are executed.
Is there a way I could see which iteration is currently running from the VB user interface? I would like to write this information into the text box so the user will have a better control. That means that within the call, there should be some interactive control between VB and DLL.
Can you, please, give me any help?
Thank you very much.
The code in VB is written so that in each loop, arrays are refilled with new values and program calls DLL. DLL then runs number of simulation iterations (within a single call) and sends results back to VB in arrays. New arrays are refilled and so on until all simulation scenarios are executed.
Is there a way I could see which iteration is currently running from the VB user interface? I would like to write this information into the text box so the user will have a better control. That means that within the call, there should be some interactive control between VB and DLL.
Can you, please, give me any help?
Thank you very much.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm pretty sure it appeared earlier (maybe in the old Forum but Search facility seems to be defunct there) but I can't find it either. There are several ways, the most simple being using a VB callback routine passed through fortran's arg-list (as EXTERNAL). The routine should be called, say, at the end of iteration loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to make a simple example, but probably the declaration in VB is wrong.
This is the fortran code:
SUBROUTINE callingback(valuein, cbsub)
!DEC$ ATTRIBUTES DLLEXPORT :: callingback
!DEC$ ATTRIBUTES ALIAS : 'callingback' :: callingback
INTERFACE
SUBROUTINE cbsub(c1)
INTEGER c1
END
END INTERFACE
REAL valuein
REAL array1(1000, 1000)
REAL array2(1000, 1000)
INTEGER c1
c1 = 0
CALL RANDOM_NUMBER(array1)
c1 = 1
CALL cbsub(c1)
CALL RANDOM_NUMBER(array1)
array2 = array1 * valuein
c1 = 2
CALL cbsub(c1)
END SUBROUTINE callingback
And here is the declaration in VB module:
Public Declare Sub callingback Lib "c:My DocumentsCallBackDebugCallBack.dll" (valuein As Single)
Here is how I call it from form1
Private Sub Command1_Click()
valuein = 5
Call callingback(valuein)
End Sub
And here is the callback subroutine that I place in another module:
Public Sub cbsub(c1 As Long)
Form1.Text1.Text = c1
End Sub
I tried to follow the callback VF example, but unfortunatelly there is no description of VB code.
Thank you very much for your advice. Milan2
This is the fortran code:
SUBROUTINE callingback(valuein, cbsub)
!DEC$ ATTRIBUTES DLLEXPORT :: callingback
!DEC$ ATTRIBUTES ALIAS : 'callingback' :: callingback
INTERFACE
SUBROUTINE cbsub(c1)
INTEGER c1
END
END INTERFACE
REAL valuein
REAL array1(1000, 1000)
REAL array2(1000, 1000)
INTEGER c1
c1 = 0
CALL RANDOM_NUMBER(array1)
c1 = 1
CALL cbsub(c1)
CALL RANDOM_NUMBER(array1)
array2 = array1 * valuein
c1 = 2
CALL cbsub(c1)
END SUBROUTINE callingback
And here is the declaration in VB module:
Public Declare Sub callingback Lib "c:My DocumentsCallBackDebugCallBack.dll" (valuein As Single)
Here is how I call it from form1
Private Sub Command1_Click()
valuein = 5
Call callingback(valuein)
End Sub
And here is the callback subroutine that I place in another module:
Public Sub cbsub(c1 As Long)
Form1.Text1.Text = c1
End Sub
I tried to follow the callback VF example, but unfortunatelly there is no description of VB code.
Thank you very much for your advice. Milan2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That code will crash and burn since you have mismatched declarations of callingback -- the second argument is missing in VB. You should pass address of cbsub there. However, sorry, I don't know how to do it -- I'm not quite familiar with VB. Marco?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Milan,
maybe MS KB Q171729 (have problem with url) will be of some help.
A.
maybe MS KB Q171729 (have problem with url) will be of some help.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your help. I made a search in the old forum and on the internet. The only step by step example I found was the Q181578 that you proposed. I tried to follow it with my example, but I was not successful.
I started to think about some modifications in my Fortran code with the option to call each iteration using another loop in visual basic, but I would still rather use callbacks that are (I think) much better for my program.
I give my new code here following the same example as above. Please, be so kind and let me know if you have any ideas what might be the problem.
Here is the declaration in general declaration section in Form1 in VB:
Private Declare Sub callingback Lib "c:My DocumentsCallBackDebugCallBack.dll" (valuein As Single)
This is the code in Click event of the Command Button (placed on Form1):
Private Sub Command1_Click()
valuein = 5
Call callingback(valuein, AddressOf callback)
End Sub
Finally, here is the callback subroutine in VB module:
Sub callback(c1 As Long)
Form1.Test1.Text = c1
End Sub
The fortran code:
SUBROUTINE callingback(valuein, callback)
!DEC$ ATTRIBUTES DLLEXPORT :: callingback
!DEC$ ATTRIBUTES ALIAS : 'callingback' :: callingback
INTERFACE
SUBROUTINE callback(c1)
INTEGER c1
END
END INTERFACE
REAL valuein
REAL array1(1000, 1000)
REAL array2(1000, 1000)
INTEGER c1
c1 = 0
CALL RANDOM_NUMBER(array1)
c1 = 1
CALL callback(c1)
CALL RANDOM_NUMBER(array1)
array2 = array1 * valuein
c1 = 2
CALL callback(c1)
END SUBROUTINE callingback
Thank you very much,
Milan
I started to think about some modifications in my Fortran code with the option to call each iteration using another loop in visual basic, but I would still rather use callbacks that are (I think) much better for my program.
I give my new code here following the same example as above. Please, be so kind and let me know if you have any ideas what might be the problem.
Here is the declaration in general declaration section in Form1 in VB:
Private Declare Sub callingback Lib "c:My DocumentsCallBackDebugCallBack.dll" (valuein As Single)
This is the code in Click event of the Command Button (placed on Form1):
Private Sub Command1_Click()
valuein = 5
Call callingback(valuein, AddressOf callback)
End Sub
Finally, here is the callback subroutine in VB module:
Sub callback(c1 As Long)
Form1.Test1.Text = c1
End Sub
The fortran code:
SUBROUTINE callingback(valuein, callback)
!DEC$ ATTRIBUTES DLLEXPORT :: callingback
!DEC$ ATTRIBUTES ALIAS : 'callingback' :: callingback
INTERFACE
SUBROUTINE callback(c1)
INTEGER c1
END
END INTERFACE
REAL valuein
REAL array1(1000, 1000)
REAL array2(1000, 1000)
INTEGER c1
c1 = 0
CALL RANDOM_NUMBER(array1)
c1 = 1
CALL callback(c1)
CALL RANDOM_NUMBER(array1)
array2 = array1 * valuein
c1 = 2
CALL callback(c1)
END SUBROUTINE callingback
Thank you very much,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now it looks quite OK. As I said, I'm not familiar enough with VB; however, I'm suspicious about statement
My guess is that it doesn't update the form immediately. Is there perhaps a method Form1.Test1.Update() or something like that?
Could you put a breakpoint inside callback and verify that it's indeed called?
Form1.Test1.Text = c1
My guess is that it doesn't update the form immediately. Is there perhaps a method Form1.Test1.Update() or something like that?
Could you put a breakpoint inside callback and verify that it's indeed called?

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