Calling C++ DLL from FORTRAN ... Application failed to initialize properly



I have this dll that I wrote in VC++.NET. I've exported some functions
that I know work when called from C++, VB, VBA, HTML (when I regasm(ed)
it). So it works ... but they want me to call it from FORTRAN, writen
in Intel Fortran. When I try to run the fortran code, I get
"Application failed to initialize properly (0xc0000142) Click on OK to
terminate the program"

Here's what I have ...

In my *.h file I have ...

extern "C"

{

__declspec(dllimport) void __stdcall IterateInputFile(String*);

__declspec(dllimport) void __stdcall IterateInputArray(double*,
double*);

}



In my *.cpp file I have ...

void __stdcall IterateInputFile(String* FilePath)

{

STWT::CSTWT* ws = __gc new STWT::CSTWT();

ws->Iterate1(FilePath);

FilePath = FilePath->Replace(S".xml",S".out.xml");

ws->OnFileSaveXml(FilePath);

}

void __stdcall IterateInputArray(double* InputArray, double*
OutputArray)

{

STWT::CSTWT* ws = __gc new STWT::CSTWT();

ws->Iterate2(InputArray);

ws->PopulateOutputArray(&OutputArray[0]);

}



in my FORTRAN project settings ....

Additional Dependancies = "$(OUTDIR)/STWT.lib" (the lib and dll is
located with the f90 exe file)



and .. in my *.f90 file, I have ....

program STWT_FORTRAN

implicit none


REAL *8 Input(92)

REAL *8 Output(56)

character(len=256) FileName

interface

subroutine IterateInputArray(InputArray,OutputArray)

!DEC$ ATTRIBUTES STDCALL, DLLIMPORT, alias: "_IterateInputArray@8" ::
IterateInputArray

REAL *8 InputArray(92)

REAL *8 OutputArray(56)

end subroutine IterateInputArray


subroutine IterateInputFile(InputFile)

!DEC$ ATTRIBUTES STDCALL, DLLIMPORT, alias: "_IterateInputFile@4" ::
IterateInputFile

character(len=256) :: InputFile

end subroutine IterateInputFile

end interface


print *, 'Hello World'


FileName = "D:\\test.stwt.xml"


call IterateInputFile(FileName)


print *, 'Good Bye, Cruel World!'

end program STWT_FORTRAN

*****************

When I run the exe, I get the "Application failed to initialize
properly (0xc0000142) Click on OK to terminate the program" error.

Other behaviors are ...

1) When I comment out the "call IterateInputFile(FileName)" ... the
code runs and I get the console messages.

2) When I run in debug mode, the code fails before reaching the "hello
world" and throws me into "malloc.c" in the void * __cdecl
_heap_alloc_base (size_t size) function.

Any clue?

Thanks,

Jason

.



Relevant Pages

  • Re: intel compiler and [REFERENCE] keyword?
    ... Wouldn't that change the binary interface? ... SUBROUTINE SYSFNCBIND ... This is trouble - Fortran LOGICAL does not match ... This binary interface has been stable for about 10 years and has been ...
    (comp.lang.fortran)
  • Re: getting env. variables in gfortran...
    ... Fortran standard (processes, threads, priorities, interprocess ... POSIX functions and Fortran 77. ... POSIX standard itself, not just to the fortran 77 interface. ...
    (comp.lang.fortran)
  • Re: F90 to C interface
    ... I had a while ago a similar problem (interfacing Fortran code with C ... libraries); theoretically you would be able to use the Fortran2003 ... A Fortran module was also written containing interface ... Regarding arrays, you have to be careful: ...
    (comp.lang.fortran)
  • Re: [F03 C-interoperability] Correct way to do C_PTR (char *) to CHARACTER vector conversion
    ... I am planning to embark on a project in Fortran 95. ... that I needed to interface against zlib to compress data. ... FUNCTION ZLIBVERSION BIND ...
    (comp.lang.fortran)
  • Re: GUI for fortran
    ... interface to a program for which the computation is more important than ... That is, of course, a large proportion of Fortran ... but you will be interfacing with the GUI using a Windows DLL. ... a useful tool to build the Delphi DLL ...
    (comp.lang.fortran)