DLL compilation, error at runtime R6034

DLL compilation, error at runtime R6034

Hi all,

I wrote a DLL for windows in fortran language, using the DEC directives:

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: SOLVER
!DEC$ ATTRIBUTES ALIAS:'SOLVER' :: SOLVER

because I want to call it from a vb.net program. From the program in vb.net, the DLL is called with:

    Public Declare Auto Sub SOLVER Lib "solver.dll" _
    (ByRef N As Double(,), ByRef V As Integer(,), ByRef C As Integer(,), ByRef car As Double(,), _
     ByRef E As Double, ByRef ni As Double, ByRef ro As Double, ByVal U As Double(,), _
     ByRef Nmax As Integer, ByRef Cmax As Integer, ByRef IERR As Integer)

I'm using Intel Composer XE 2011. Under "Properties/Fortran/Runtime libraries" I set "Multithread DLL (/libs:dll /threads)", and "Use Intel Math Kernel Library" is set to "Sequential (/Qmkl:sequential)" because I need Lapack routines.

I compile in "Release", with no manifest (I tried also with it, same error). The compiled DLL is in the same directory of the vb.net EXE, and I have already put all the libraries requested by "Dependency Walker" for the solver.dll in the same dir.

I get the sollowing error when I try to run the vb.net code (in Release, debug target for "Mixed Platform" or "Any CPU" with "x86" directive):

Microsoft Visual C++ Runtime Library
Runtime error!
Program: C:\...
R6034
An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support team for more information.

and then the program stops and gives me the error:

Impossibile caricare la DLL 'solver.dll': Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita. (Eccezione da HRESULT: 0x8007045A).

that translated to English it is more or less: "Impossible to load the DLL 'solver.DLL': Initialization routine of the dynamic link library (DLL) not successful (Exception from HRESULT: 0x8007045A)."

Please help, I cannot solve this.

Thanks,

Giovanni

13 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
iliyapolak's picture

I think that NtLoader could not find the dllmain function in solver.dll or the OS loader's algorithm cannot find the solver.dll library.Inspect with dependency walker if the dllmain function is present in solver.dll.If you are experienced with windbg you can run your app under windbg and enable so called "loader snaps" next you will be given  a detailed information about the various loaded dlls and initialization routines in those dlls.

Can you explain how to inspect the DLL to find out the dllmain function? I cannot figure it out in Dependency Walker.

As additional information, know that the DLL works fine if called from another Fortran program, with the DECs (no STDCALL):

!dec$ attributes dllexport::SOLVER

Giovanni

Steve Lionel (Intel)'s picture

The problem you're having is related to the Microsoft Visual C++ runtime DLLs that are used indirectly by the Fortran DLL. You can't copy those DLLs to a folder the way you do for Fortran DLLs, you have to use Microsoft's redistributables installer for the appropriate Visual Studio version.

If you know that your Fortran DLL is not going to be called by Fortran, it is probably better to set the Fortran project to link against the static multithreaded library (not DLL). Then you won't have these extra dependencies.

Steve

Thanks for the suggestion, but as far as I know I cannot use .lib in vb.net.

None of the MSVCRT libraries are in the program folder, I know they must be installed on the system via Microsoft's redistributables.

Finally, using the DEC directive:

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS: 'SOLVER' :: SOLVER

as suggested from you in another post, I got the same error.

Giovanni

Steve Lionel (Intel)'s picture

I am not saying to build a .lib, but rather to specify that your DLL links to the static runtime libraries.

This is not an issue about your Fortran code, but you do need to specify a directive such as that for use with VB.

Which Visual Studio version did you use to build the DLL? Did you build a Debug or Release configuration? (It needs to be Release.)

Steve

Ok, I set the multithreaded library (not DLL) and it generates the DLL.

Now I get System.AccessViolationException when I call the DLL, I cannot get no more info. I tried setting the "Unmnanaged code" option for debug in VS, but no more info become available.

I use VS 2008 and I compile in Release config.

Giovanni

Steve Lionel (Intel)'s picture

The access violation is probably happening on the VB side. Can you build a debug configuration and debug it locally?

It looks to me as if you're passing arrays. If so I think you need to say ByVal in the VB declaration. ByRef will give you SafeArrays. You can deal with those too in Fortran - there's a sample provided - but it's more complicated. I am not sure how multiple dimensions will work with the ByVal method.

Steve

By trying it seems that I found a solution. The DLL must declared as (no arrays specified):
Public Declare Auto Sub SOLVER Lib "solver.dll" ( _

ByRefNAsDouble,ByRefVAsInteger,ByRefCAsInteger,ByRefcarAsDouble, _

ByRefEAsDouble,ByRefniAsDouble,ByRefroAsDouble,ByRefUAsDouble, _

ByRefNmaxAsInteger,ByRefCmaxAsInteger,ByRefIERRAsInteger)

Then you shall pass by reference the 1st item of each array:

CallSOLVER(Nt(0, 0), Vt(0, 0), Ct(0, 0), cart(0, 0), Em, ni, ro, U(0, 0), Nmax, Cmax, IERR)

and everything works.

I don't know exactly what happens but it is correct.

Thanks for the help,

Giovanni

>>...
>>R6034
>>An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support
>>team for more information.
>>...

These reasons are possible:

- The application and DLL are built with different C-Runtime libraries ( for example, threaded vs / with non-threaded, etc )
- The application and DLL are built with different versions of C-Runtime libraries ( for example, CRT-libraries from VS2005 vs. CRT-libraries from VS2008, etc )
- A manifest is Not embedded to your DLL and take a look at: msdn.microsoft.com/en-us/library/ms235560(v=vs.80).aspx for more information

I also experienced a similar problem some time ago:

Forum topic: C Runtime error R6034 in an OpenMP application
Web-link: software.intel.com/en-us/forums/topic/279294

And here is one more:

Forum topic: Runtime Error R6034, An application has made an attempt to load the C runtime lib incorrectly
Web-link: forums.asp.net/t/1243247.aspx/1

Thank you Sergey,

regarding the first link you gave me, I solved without manifest. For the second link, the link in it is broken (http://msdn2.microsoft.com/en-us/library/ms235560.aspx).

Giovanni

iliyapolak's picture

>>>Can you explain how to inspect the DLL to find out the dllmain function>>>

You can use the free version of IDA Pro.Simply load the your dll file and disassemble it.Beside the IDA you can use also dumpbin which will help you to locate the dll's entry point.Bear in mind that the error result which you received is very general  and it could not mean that dllmain is not present.

Steve Lionel (Intel)'s picture

The error you got is simply caused by having the MSVC DLL shared assembly not installed, or by copying one of the MSVCRxx.DLL files into a place where Windows will load it. There is no need to go digging for DllMain, etc.

Steve

Login to leave a comment.