- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I have been working on converting several Fortran DLLs first to DLLs callable from Visual Basic, and now to DLLs callable from VBScript.
I succeeded in the first task (calling Visual Fortran from Visual Basic) with no problem. Now I need help converting my Fortran subroutines to COM DLLs callable from VBScript. I am able to do it when my Fortran subroutine returns only one value. However, I do not know what to do for cases when the subroutine returns several output values. I understand that when I specify arguments for object methods in the Fortran COM Server Wizard, only one argument with Intent Out can have a return value. This makes sense since object methods are functions, but what to do about subroutines? I was under impression that COM Server Wizard will create a wrapper, and implementation of the method is cut and paste of my original Fortran DLL. Where am I going wrong and what am I missing? Do I need to completely re-write my Fortran subroutines if they return more than one argument?
A simple Fortran subroutine is listed below. It takes three input arguments (integer, string, and float) and returns integer tripled, a concatenated string, and the float doubled.
SUBROUTINE Test_VB (INT_ARG, STR_IN, FLOAT_ARG, INT_OUT, STR_OUT, NUM)
IMPLICIT NONE
! Specify that Test_VB is exported to a DLL
! and that the external name is 'Test_VB'
!DEC$ ATTRIBUTES DLLEXPORT :: Test_VB
!DEC$ ATTRIBUTES ALIAS:'Test_VB' :: Test_VB
INTEGER INT_ARG,INT_OUT
REAL FLOAT_ARG,NUM
CHARACTER*(*) STR_IN, STR_OUT
! This routine converts INT_ARG to a string,
! appends the string value to STR_IN and stores it
! in STR_OUT. It also triples the integer and doubles
! the float.
!
CHARACTER*5 INT_STR
WRITE (INT_STR,'(I5)') INT_ARG
INT_OUT = 3*INT_ARG
STR_OUT = STR_IN // INT_STR
NUM = FLOAT_ARG*2.0
RETURN
END
Please let me know what I would need to specify in the Fortran COM Server Wizard to make this work. Again, I was able to get this to work as COM DLLs form ASP when I separated the Fortran routine into three routines returning one value each.
Your help is greatly appreciated.
Maria.
I have been working on converting several Fortran DLLs first to DLLs callable from Visual Basic, and now to DLLs callable from VBScript.
I succeeded in the first task (calling Visual Fortran from Visual Basic) with no problem. Now I need help converting my Fortran subroutines to COM DLLs callable from VBScript. I am able to do it when my Fortran subroutine returns only one value. However, I do not know what to do for cases when the subroutine returns several output values. I understand that when I specify arguments for object methods in the Fortran COM Server Wizard, only one argument with Intent Out can have a return value. This makes sense since object methods are functions, but what to do about subroutines? I was under impression that COM Server Wizard will create a wrapper, and implementation of the method is cut and paste of my original Fortran DLL. Where am I going wrong and what am I missing? Do I need to completely re-write my Fortran subroutines if they return more than one argument?
A simple Fortran subroutine is listed below. It takes three input arguments (integer, string, and float) and returns integer tripled, a concatenated string, and the float doubled.
SUBROUTINE Test_VB (INT_ARG, STR_IN, FLOAT_ARG, INT_OUT, STR_OUT, NUM)
IMPLICIT NONE
! Specify that Test_VB is exported to a DLL
! and that the external name is 'Test_VB'
!DEC$ ATTRIBUTES DLLEXPORT :: Test_VB
!DEC$ ATTRIBUTES ALIAS:'Test_VB' :: Test_VB
INTEGER INT_ARG,INT_OUT
REAL FLOAT_ARG,NUM
CHARACTER*(*) STR_IN, STR_OUT
! This routine converts INT_ARG to a string,
! appends the string value to STR_IN and stores it
! in STR_OUT. It also triples the integer and doubles
! the float.
!
CHARACTER*5 INT_STR
WRITE (INT_STR,'(I5)') INT_ARG
INT_OUT = 3*INT_ARG
STR_OUT = STR_IN // INT_STR
NUM = FLOAT_ARG*2.0
RETURN
END
Please let me know what I would need to specify in the Fortran COM Server Wizard to make this work. Again, I was able to get this to work as COM DLLs form ASP when I separated the Fortran routine into three routines returning one value each.
Your help is greatly appreciated.
Maria.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're going way off track.
The subroutines become simply functions that have a hResult return value. The argument list stays the same and gets returned like your usual subroutines.
Just describe the arg list on the COM-server wiz'd and copy the body of the subroutine into the shell the wiz'd makes for you. Be sure to set the intent to out or inout for each arg in the wiz'd.
One other thing, VB is has some unique quirks in the COM realm. Passing string and logical is a little tricky and do not try to pass things like complex, int(1).
There was a thread in the old forum about this. search for Rahzan.
The subroutines become simply functions that have a hResult return value. The argument list stays the same and gets returned like your usual subroutines.
Just describe the arg list on the COM-server wiz'd and copy the body of the subroutine into the shell the wiz'd makes for you. Be sure to set the intent to out or inout for each arg in the wiz'd.
One other thing, VB is has some unique quirks in the COM realm. Passing string and logical is a little tricky and do not try to pass things like complex, int(1).
There was a thread in the old forum about this. search for Rahzan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you can have multiple output arguments but only 1 "return value". A "return value" is sort of a syntatic thing in COM. In actuality, all COM methods return an HRESULT. But IDL allows you to mark the final output argument as a "return value". This simply changes the syntax that you use in languages like VB to invoke the method. That is, the "return value" argument will look like a return value in the VB syntax. If you did not mark the argument as a "return value", it would simply be another argument in the calling argument list.
Leo
Leo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim and Leo,
Thanks so much. Now I understand the source of my confusion. I will try what you suggest and report back.
Maria.
Thanks so much. Now I understand the source of my confusion. I will try what you suggest and report back.
Maria.
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