- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to run a .NET assembly from fortran. However,it crashes with 'blabla has triggered a breakpoint.' when calling the assembly. I know that the assembly and COM wrapper is working because it works from VB6.
Here I suspect that my string definition is not correct. Probably a story about pointer ?
Here are the code ..
------- VB 6 Working Code ---------------
Set o = CreateObject("My.Library")
MsgBox (o.Version) <= o.version is a string
---------- End of Code --------------------
------------- Fortran Not Working Code ---------
integer(4) status,Obj
CHARACTER(300) CofVersion
call COMInitialize(status)
call COMCreateObject("My.Library", Obj, status) <= Obj is not null
status = $ILibrary_GetVersion(Obj, CofVersion)
------------- End of Code --------------------------
-----------Mod Wizard Generated Code ----------
INTEGER(4) FUNCTION $ILibrary_GetVersion($OBJECT, pRetVal)
IMPLICIT NONE
INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
CHARACTER(LEN=*), INTENT(OUT) :: pRetVal ! BSTR
INTEGER(4) $RETURN
INTEGER(INT_PTR_KIND()) $VTBL ! Interface Function Table
POINTER($VPTR, $VTBL)
INTEGER(INT_PTR_KIND()) $BSTR_pRetVal ! BSTR
INTEGER(4) $STATUS
$BSTR_pRetVal = NULL
$VPTR = $OBJECT ! Interface Function Table
$VPTR = $VTBL + 60 ! Add routine table offset
ILibrary_GetVersion_PTR = $VTBL
$RETURN = ILibrary_GetVersion($OBJECT, $BSTR_pRetVal) <= Crashes
$STATUS = ConvertBSTRToString($BSTR_pRetVal, pRetVal)
CALL SysFreeString($BSTR_pRetVal)
$ILibrary_GetVersion = $RETURN
END FUNCTION $ILibrary_GetVersion
INTERFACE
INTEGER(4) FUNCTION ILibrary_GetVersion($OBJECT, pRetVal)
INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
INTEGER(INT_PTR_KIND()), INTENT(OUT) :: pRetVal ! BSTR
!DEC$ ATTRIBUTES REFERENCE :: pRetVal
!DEC$ ATTRIBUTES STDCALL :: ILibrary_GetVersion
END FUNCTION ILibrary_GetVersion
END INTERFACE
POINTER(ILibrary_GetVersion_PTR, ILibrary_GetVersion) ! routine pointer
------------- End of Code -----------------------------
Any help would be greatly appraciated.
Regards,
Vincent
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Invalid address specified RtlFreeHeap(00150000, 001644c8)" ?
If so, welcome to the club. I have posted a similar problem recently about accessing a couple of the COMDLG32.OCX methods using the same Module Wizrd approach. In my case it would seem somewhere a DLL is using a run-time library routine to release a heap created by another dll or thread and using the wrong pointer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had a look at the Modules generated by the FORTRAN wizard and that is an interesting bowl of spaghetti.
Steve: Another issue with the FORTRAN help files. The tools menu has a sub menu called Intel etc, below this submenu is a single element the Fortran Wizard. The help files show it at the higher level making it easy to find, you had me stumped for about a minute, while I tried to find the wizard.
JMN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not able to continue testing unless we are looking at the same object. Can we get some sort of dummy object that we can all use to see what the problems are?
JMN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your comment on the help has been passed on to the writers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It was a real eye-opener that strings declared in Microsoft vb.net were crashing during Microsoft Windows calls! But the .net managed memory is completely different and very strange.
For instance, the OpenPrinterW call from vb.net looks like this:
[vb]Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterW" (ByVal pPrinterName As System.IntPtr, ByRef phPrinter As System.IntPtr, ByVal pDefault As Integer) As Integer Dim printerNamePtr As IntPtr = Marshal.StringToHGlobalUni(strRequestedPrinter) result = OpenPrinter(printerNamePtr, hPrinter, 0)[/vb]I'm guessing that returning from Windows API or Fortran to .net managed memory requires this to be undone. Can't say for sure but you can judge whether it is worth looking at. Don't forget that most .net strings are unicode, whereas Fortran strings are not unless you deliberately convert them.

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