- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There have been several threads in this forum about passing strings (usually file paths for read operations) from VB2005 to a .dll written in IVF. These were very helpful to me in trying to do th same thing. After I got that working, I attempted to pass a string that was read from the file along with a bunch of numeric data back to the VB calling routine with no success at all.
The closest I came was being able to see the string in the dll code after setting a breakpoint just before the dll returned.
I have attached a file with some code snippets and comments and would be very grateful for any pointers.
As an aside, I'd like to mention that on the way to getting the file pathname string from VB to IVF I learned that you can't be cavalier about the ansi/unicode/auto attribute in the VB delare statement, no matter how enticing the term "AUTO" may sound. It needs to be "ansi" or nothing at all since "ansi" is the default. If you use AUTO or UNICODE without (I suppose) additional programming details you will get a few characters of gibberish instead of your string, even if all the other code is OK.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have not looked at your code, but I would strongly recommend using the "BSTR" routines to send strings back to VB. I don't think you can do it with normal Fortran code. See one of the provided VB-calling-Fortran samples for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have not looked at your code, but I would strongly recommend using the "BSTR" routines to send strings back to VB. I don't think you can do it with normal Fortran code. See one of the provided VB-calling-Fortran samples for details.
I started researching "BSTR" routines based on your suggestion and didn't find much in the IVF or MS VS2005 help info. I also downloaded the IVF 11.066 trial version to look at the mixed programming samples, but the ones I found didn't provide much help. I did find out that VB and the CLR of .NET really doesn't want you messing with it's strings. I also discovered the existence of "stringbuilder", but haven't figured out how to use it yet.
I know I'm going to have to get up to speed on this eventually, but for my present situation I only need to return a single 48 character string to the VB caller. I found that a byte array with appropriate glue code in the caller and the subroutine does the job quite well.
For future reference, I'd be delighted for any links and/or pointers to good intro material on passing strings to managed code.
Thanks very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at the VB.NET-Safearrays sample for an example of using BSTR. You can find documentation of the Fortran-provided routines for manipulating BSTRs, such as ConvertBSTRToString, in the compiler docs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at the VB.NET-Safearrays sample for an example of using BSTR. You can find documentation of the Fortran-provided routines for manipulating BSTRs, such as ConvertBSTRToString, in the compiler docs.
In the compiler INCLUDE files you should be able to find a reference to a Bitstring data type, such As
TYPE T_SAFEARR_BSTR
SEQUENCE
integer(ULONG) Size ! knowns ULONG
integer(LPVOID) aBstr ! star wireBSTR *
END TYPE
If you USE the appropriate module (DFWINTY in my case, as I use Compaq Visual Fortran) you will find it and you can then define a bitstring-type for use in returning your string to VBasic.
Suppose the type is defined thus:
TYPE T_SAFEARR_BSTR
SEQUENCE
integer(ULONG) Size ! knowns ULONG
integer(LPVOID) aBstr ! star wireBSTR *
END TYPE
Then the following code may work:
Type (T_SAFEARR_BSTR) MyBitString
Character(100) MyString
MyString="This is my null-terminated character string"//CHAR(0)
MyBitString%Size=LEN_TRIM(MyString)
MyBitSTring%aBstr=LOC(MyString)
You should therefore provide an INTENT(OUT) argument for the Bit-string to be returned to VBasic.
As Steve pointed out, you could also define a VARIANT and make it a Bit-String Type and return that.
(On further reading, I think there may be issues regarding freeing the memory allocation for the string when it is no longer neededon the VBasic side,whichmay only be solved by using SysAllocString to populate the Bit String structure. This latter function returns a pointer to the Bit-string it populates. The memory can then be freed by using SysFreeString function)
- 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
- 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
Sorry for the empty post. I am having difficulty downloading your attachment (vbcallsfortran.zip). I keep getting a blank download page. Would you mind adding the file again? Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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