>When passing strings from VB to Fortran, you need to keep in mind that VB
>stores strings as BStrings. This format is basically not compatible with
the
>one used by Fortran. BStrings are wide strings (i.e. each character takes 2
>bytes), they are null terminated (actually double-null terminated), and
have
>the length of the string right in front. A pointer to a bstring points to
>the first character of the string. As a rule, BStrings should only be
>modified through the supplied OLE-API, so you are not supposed to change a
>Bstring from inside Fortran (unless you do it calling the appropriate
>OLE-API). Now, the trick to pass BStrings from VB to Fortran is to do it by
>value. In the VB end, you declare the Fortran sub as:
>MyText As String)
>on the Fortran end, you declare the subroutine as
>stdcall subroutine MyStringSub(StringPtr)
>character(len=255) MyString
>pointer (StringPtr, MyString)
>:
>:
>You must make sure that MyString is long enough for the strings you are
>passing. Also, MyString will be null terminated, so you have to scan the
>string to find its length. This trick works because VB will convert the
>passed Bstring into a Multibyte string when calling API functions by Value.
>So what you get in your Fortran side is basically a pointer to a normal
>C-style string.
>For those of you that have been struggling with this problem, you should
>visit our web pages in about two more weeks. We will publish a library of
>subroutines (actually, a portion of our f90ADO library) that will allow
>passing bstrings back and forth between Fortran and VB.
>Marco A. Garcia
>Canaima Software
>3981 Utah St.
>San Diego, CA 92104
>U.S.A.
>http://www.canaimasoft.com
>Developers of f90SQL and f90ADO,
>the Complete Database Connectivity Solution for Fortran
>>Hi all
>>I am using Absoft Fortran 77 to create DLL's and I then call them from
>>VBA under Excel97. I have been doing this for quite some time now.
>>I have no trouble in sending variables of doubles and integers OR arrays
of
>>integers or doubles through to the DLL's.
>>STRINGS, however, seems to be a problem. I have never send a string
through
>to
>>a DLL and this now stumbles me.
>>I tried various ways. I declare the string in VBA as for instance
>>Byval StringVar as String
>>I then dimension the string to be a fixed length like
>>Dim StringVar as String*8
>>or
>>Static StringVar as String*8
>>On the Fortran side I then have
>> STDCALL subroutine test(....., StringVar,...)
>> character*8 stringvar
>>This does not work. What is wrong??
>>I also tried to have
>> STDCALL subroutine test(....., StringVar,...)
>> character*(*) stringvar
>>in my fortran code. It still does not work.
>>The whole program is working fine because if I do not send a string
>through,
>>i.e., if I make stringvar to be a double and I just work with stringvar as
>a
>>real*8 then the program works 100%.
>>But, the program would be a bit more efficient if I could send a string
>>through.
>>How?.
>>If anyone can help, please let me know.
>>Thanks
>>Antonie Kotze