Silverfrost Forums

Welcome to our forums

linking with C++ DLLs

16 Jun 2006 9:40 #745

Does anyone know the answer to the following?

I have a created a FNT99 DLL (f95fun.dll) that calls functions in a C++ DLL (say cppfun.dll).

Compiler SWITCHES: /IMPORT_LIBcppfun.lib (associated lib for the dll produced by VisualC++7)

Linker SWITCHES: -EXPORTALL

I have no compilation errors but the following run-time error: 'The procedure entry point __adjust_stack_f could not be located in the dynamic link library salflibc.dll'

cppfun.lib has a function

      __imp__CloseFile@0

(i.e. a DLL import void function)

this has been declared in the fortran include as stdcall CloseFile 'CloseFile' (val): integer*4

The linker complains: Linking... WARNING - Default LibMain being provided WARNING the following symbols are missing: Closefile

thanks Clint

17 Jun 2006 12:21 #746

Clint

If your code will compile with the Salford C++ compiler SCC then you will find it easier to use alongside FTN95. Also if only minor changes are required to make it compile with SCC then it is better to make these changes. You can create an SCC DLL from Plato and then create a reference to it in another project. The easiest approach is to use extern 'C' rather than STDCALL in your C++ and to interface using C_EXTERNAL in your Fortran.

If you end up using Visual C++ then you should not use /IMPORT_LIB which is for Fortran DLLs. There is a section on STDCALL (and importing from a STDCALL C++ DLL ) in the help file which you will need to work through.

Basically you need to create your own header files that are like win32api.ins etc. Once you have these interfaces, you can link in the ordinary way. You can create a reference to the DLL in Plato but initially I would try leave the STDCALL switch (in the Reference properties) switched off because (if my memory serves me correctly) this switch is equivalent to using /IMPORT_LIB. I can check out the details if you have problems at this point.

You may need to check out my comments by looking in the help file but basically you need to work through the section in the help file that describes how to import a C/C++ DLL using either C_EXTERNAL or STDCALL interfaces.

19 Jun 2006 2:20 #747

Thanks Paul,

The problem is that I need to use DLLs that have been generated by other projects using MS VC7 and produce further DLLs.

Unfortunately, searching for 'STDCALL C++ DLL' in the salford help produced only 2 results: Calling FTN95 DLL from Visual Basic Comment Embedded directives.

The PDF files from the download are both F77 manuals and so it would be very helpful to get the FTN95 manuals.

cheers Clint

19 Jun 2006 4:52 #748

The solution is to include the C++ DLL (cppfun.dll) in the slink.

slink.exe -OUT:'Debug\Win32\experiment.exe' Debug\Win32\test.obj cppfun.dll

How do you achieve this when integrated with Visual Studio or Plato? (Instead of editing link.lst by hand or manually calling slink)

How do you get the salford compiler to produce a lib file for other compilers what cannot extract the information directly from a DLL?

cheers Clint

19 Jun 2006 11:48 #751

Clint

You can access a DLL from Visual Studio or Plato by creating a Reference to it from the Project/Solution Explorer window (I assume that this information is in the 'Getting started' sections of the help file).

To create a library archive, create a project for a DLL and then change its type (in the Project Properties) to a .LIB.

Please login to reply.