
Mixed language programming DLL , C++, VB/VBA, Fortran
Quote:
> I need to create a DLL from C++ and call some of its functions from VB/VBA
> and Fortran.
Which Fortran compiler? I have some familiarity with using Fortran
with other languages, including C/C++ and VB, but I'm not sure how many
other readers of the VC groups do. You may want to include
comp.lang.fortran in the newsgroups list for any questions along those
lines.
Quote:
> While creating the DLL I use 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)
Using CString in this context is a very bad idea. The native VB string
type is BSTR, and otherwise you should use some variety of char *.
While it might be theoretically possible to construct something that
matches the internal layout of the MFC CString in VB, IMO it's much
more trouble than it's worth. Better to take a char * and, if
necessary, convert it.
Beyond that, VB requires the __stdcall calling convention, which it
doesn't appear you used.
So, for example,
int __stdcall ExtractInt(char * Line);
and beware of memory management and ownership issues.
Quote:
> Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer
C/C++ int != VB Integer
Private Declare Function ExtractInt Lib "MyDll.dll"
Quote:
> 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)?
There should be some documentation in MSDN. I'm not sure, offhand,
where to find it.