Mixed language programming DLL , C++, VB/VBA, Fortran
-
I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:
-
I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:
-
I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:
a) I would look on the MSDN CD's first. If you can't find it there, a decent advanced book about VB would probably have the info you need. Your DLL can use MFC (statically linked is my advice), but it cannot be an extension DLL (it must be a "regular" DLL). You also cannot use CStrings as parameters or return values. b) I don't know anything about VB, so I can't answer that. c) You might look into writing an ATL COM DLL. It's supposed to be much easier to use from disparate languages (assuming you can use a COM DLL from within your fortran app - if not, forget this option). "...the staggering layers of obcenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001