Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28463 Discussions

Troubles migrating from Visual Studio 6.0 (Visual Fortran 6.6.0) to Visual Studio 2013 (Parallel Studio XE 2015)

Ibon_D_
Beginner
549 Views

Hello everyone,

I’m developing an upgrade from Visual Fortran 6.0 to Visual Studio 2013. It is a dynamic library based on Fortran and C++  . The migration of the project is automatically made by VS2013, so, I only change the code to adapt it to new C++  standard and add "$(IFORT_COMPILER15)\compiler\lib\ia32" to Library WinRT Directories of Microsoft.Cpp.Win32.user.

First I build the C++  project obtaining a static library, after that, I compile the Fortran project with the static library to obtain the dynamic library. This step works and I obtain the dynamic library.

Then, I’m trying to run the dll file from another project but the code breaks when it is trying to get the addresses of the library functions. The code runs properly (this part of code) when it loads the Visual Fortran 6 library. So it should be the new dll.

 

  // Attempt to load the specified dll
   m_hInstance = ::LoadLibrary(filename);
   HMODULE hm = (HMODULE) m_hInstance;
   if (0 == m_hInstance) goto cleanup;

   // Get addresses of all DLL functions
   m_pSI = (INITIALIZE*) ::GetProcAddress(hm, "Initialize");
   if (!m_pSI) goto cleanup;

   m_pGC = (GETCOUNT*) ::GetProcAddress(hm, "GetCount");
   if (!m_pGC) goto cleanup;

   m_pGP = (GETPERIOD*) ::GetProcAddress(hm, "GetPeriod");
   if (!m_pGP) goto cleanup;

 

I am able to load the dll, but when I call to GetProcAddress function, I get NULL address. And we don’t know why it cannot get addresses.

Any suggestion of what can I do?

Information of fortran and visual studio:

  • Visual Studio: Professional 2013, Version 12.0.21005.1
  • Fortran compiler: Intel® Parallel Studio XE 2015 Composer Edition for Fortran, Version 15.0.0115.12

Thank you in advance,

Ibon

0 Kudos
8 Replies
mecej4
Honored Contributor III
549 Views

I suspect that the DLL routines are built with the STDCALL conventions, especially if the project to build it was converted from a Compaq Fortran (CVF) project. If you do not need STDCALL, remove that option from the DLL project and rebuild the DLL. If you do, then specify the STDCALL attributes in the routines in your new project that call the DLL routines.

0 Kudos
Ibon_D_
Beginner
549 Views

Thanks for your answer mecej4!, but I am building the project with C REFERENCE calling convention on Fortran project and __cdecl on C++ project. Maybe I need to change them...?

0 Kudos
mecej4
Honored Contributor III
549 Views

Now that the usual suspects have been judged innocent, perhaps you can post the full code, project file(s) and build instructions, if the size of the sources is modest, or consider making up a smaller "reproducer" that contains the same bugs/features.

0 Kudos
IanH
Honored Contributor II
549 Views

Perhaps you forgot to mark the procedures in the Fortran DLL as DLLEXPORT'able, or perhaps the coffee grounds in the bottom of my cup have lost their psychic debugging ability!
 

0 Kudos
JVanB
Valued Contributor II
549 Views

Use DUMPBIN /EXPORTS on the *.DLL to see what symbols it is exporting. Also, when GetProcAddress returns NULL, see what GetLastError subsequently returns. Make sure it's not a 32/64-bit thing.

 

0 Kudos
Ibon_D_
Beginner
549 Views

Hello! Thanks for all your replies :D

I can't upload the project, confidentiality and so on...

The code for exporting the functions is like this, i don't think that it is wrong:

extern "C" 
{ 
   __declspec(dllexport) BOOL Initialize();
   __declspec(dllexport) int GetCount(); 
   __declspec(dllexport) double GetPeriod(); 
}

Using dumpbin, I realized that there aren't any symbols exporting. Neither in C++ static library nor Fortran dynamic library. So i get ERROR_PROC_NOT_FOUND error while i am using GetLastError.

I think that I am making something wrong while I'm building it,

  1. Build like static library the C++project
  2. Build like dynamic library the FORTRAN project, importing the static library in the linker.

I'm not really sure what I am doing, because it is the first time working over VS2013 so I just try to have the same properties as VC++6 in the newest version. The rest (dependencies, some properties...) were configured automatically by VS2013. So maybe I need to reconfigure the properties... dunno, I'm loose. :(

I was trying to build it reversing the order (C++ project like dynamic library and the FORTRAN project like static) but it has some a lot of linking errors :S all of them:

  • error LNK2019: unresolved external symbol
  • error LNK2001: unresolved external symbol
 error LNK2019: unresolved external symbol _a320_divmodes referenced in function "public: int __thiscall CDatapool::Initialize(void)" (?Initialize@CDatapool@@QAEHXZ)

If you have more ideas, they are welcome :D

Thank you so much,

Ibon

 

 

 

 

 

 

 

0 Kudos
mecej4
Honored Contributor III
549 Views

Ibon D. wrote:

I can't upload the project, confidentiality and so on...

If you have more ideas, they are welcome :D

Ibon

Make up a test project which displays the same problematic behavior, but is otherwise completely useless. If even that is prohibited by your confidentiality requirements, you should seek helpful in a non-public forum or with Intel Premier Support.

 

 

 

 

 

 

0 Kudos
Ibon_D_
Beginner
549 Views

Hello,

I think if I made the test project, I will not get the same problematic behavior; because of the complexity and big amount of data of the project.

Now I am focusing in the linking errors, cause I realized that the static libraries compiled in VF6.6 and VS2013 have the same exports function. I mean, I am working with C++ project like main project...

This linking error comes because of common blocks. That they are not read by project. How ca I add them?

Thank you,

Ibon

 

0 Kudos
Reply