Discussion of Intel Visual Fortran samples

Discussion of Intel Visual Fortran samples

Imagen de Steve Lionel (Intel)

Please use this thread for discussion of and asking questions about the samples I posted.

Steve
publicaciones de 36 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de gkchang

Hi Steve,


I have a quick question on the following sample file:


ExceptionHandlingGETEPTR


When compiling the solution, I've got the following error:


fatal error LNK 1104" cannot open file 'IFWIN.LIB'


Please advise how to add this reference tothe C project of the solution (though it already has the dependency to the geteptr_lib). TIA


-George


Imagen de Steve Lionel (Intel)

Tools..Options..Projects..VC++ Directories. To the list of Library directories add C:Program FilesIntelCompilerFortran9.0IA32Lib

You have to do this in general when building C applications that call Fortran code.

Steve
Imagen de guy.houlsby@eng.ox.ac.uk


I am running Visual Studio 2005 and IVF 9.1 and have a problem with running a Fortran dll from Visual Basic.


I have taken your example, which runs fine. However, if I add the following code to the fortran I get a problem:


SUBROUTINE dll_rout1 ()


IMPLICIT NONE


!DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: dll_rout1


!DEC$ ATTRIBUTES ALIAS:'dll_rout1' :: dll_rout1


character(len=4) :: dd


dd="aaa"


RETURN


END


Note that I leave your code exactly intact - my code is an additional routine that is never executed. When I press the "Do it!" button in your code I get the error:


"BadImageFormatException was unhandled"


"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"


What is very odd is that if I change "aaa" to "aaaa" in the above code then everything works fine! It seems to be someting to do with the presence of a string that is not the "right" length, but Fortran of course should cope with that. Any suggestions? ... I'd be very interested to know if your system reproduces this fault!

Imagen de guy.houlsby@eng.ox.ac.uk

I posted a question about the samples here, and it appeared for a short while and then disappeared again. How do I get a reply? (Please be patient with a novice to this game).

Imagen de Steve Lionel (Intel)

I sent you email about it.

Steve
Imagen de warwickb@calm.wa.gov.au

I have tried building the 'C_calls_Fortran' solution in Debug mode and everything links OK but on "Debug...Starting New Instance" for USEDLL I get the message that MSVCRTD.DLL is not found. I searched through the Microsoft Visual Studio 2003.NET directories and couldn't find it there but I could find MSVCRTD.LIB.

Note that the USELIB version worked fine. Note that just building USEDLL alone also has the same result as before.

Just wondering how serious this is if I want to use USEDLL as a template for calling a FORTRAN DLL I've created?
Regards, Warwick

Imagen de Steve Lionel (Intel)

You're using an old version of the compiler. As in at least a year and a half old. If you can't get a newer one, go to the Fortran..Libraries property page and choose "Single-Threaded DLL" for "Use Run-Time Library", not "Debug Single-Threaded DLL".

The problem was that the Fortran debug DLL libraries were linked to a non-redistributable MSVC 6 DLL. They aren't anymore.

Steve
Imagen de warwickb@calm.wa.gov.au

Hi,
Despite having an old compiler I have managed to get something working involving the Mixed-Language examples. Your example uses a mainline C++ program to call the FORTRAN DLL. Oracle seems to require me to call a FORTRAN routine from a C (not C++) DLL. I have tried to use the Microsoft Visual Studio wizard to create a C DLL that calls FSUB but it won't compile with the call to printf:
"error C3861: 'printf': identifier not found, even with argument-dependent lookup". Interestingly I had a similar problem previously but I got around it substituting " for and > (I think) in the #include "*.h" commands. My code is attached along with the complete error message.

I probably should be asking ORACLE for help but others may be interested in knowing how to call a FORTRAN subroutine - or DLL - from a C DLL. I'm using Visual C++ associated with Visual Studio 2003 .NET.

I got rid of printf and although it will compile, it won't create a .dll file:
"Linking...
Creating library Debug/C_DLL_CALLDLL.lib and object Debug/C_DLL_CALLDLL.exp
C_DLL_CALLDLL.obj : error LNK2019: unresolved external symbol __imp__FSUB referenced in function _CALL_FSUB
Debug/C_DLL_CALLDLL.dll : fatal error LNK1120: 1 unresolved externals"
even though I have put FDLL.lib and FDLL.dll files into the C_DLL_CALLDLL debug directory.

Regards, Warwick.

Imagen de Steve Lionel (Intel)

There is not a real difference between C and C++ in this context, other than that if you are using C++ you must take care to avoid "name mangling". Your printf error is caused likely by not including stdio.h. The DLL export library must be either added to the C project or the DLL project must be a dependent of the C project.

Steve
Imagen de mhadian

Hi Steve
i tried to compile the c_calls_fortran project. i want to use fortran dll in c++ project.
the FDLL project compiles without any problem and makes .lib and .dll files. however USEDLL project fails with these warning and errors:
Warning 1 warning C4996: 'strcpy' was declared deprecated d:c_calls_fortrancmain.cpp 56
Error 2 error LNK2019: unresolved external symbol __imp__FSUB referenced in function _main CMAIN.obj
Error 3 fatal error LNK1120: 1 unresolved externals d:C_calls_FortranUSEDLLDebugUSEDLL.exe 1

i use Intel Visual Fortran 9.1 integrated with Visual Studio 2005.
i tried to add the .lib file to USEDLL project (as i do it for using dll's in fortran) but it did not solve the problem.

Imagen de Steve Lionel (Intel)

The warning is a new thing in Visual C++ 8 (VS2005) - you can ignore it unless you want to research what new routine is to replace strcpy.


I am not sure what you did for the library issue, as adding the library works for me. Try adding it to the project itself rasther than to "source files". An alternative is to name the path to the library in the Linker Input property for Additional Dependencies.

Steve
Imagen de vivekrao4@yahoo.com

When I try to download the samples by clicking on the zipped attachement, I get a message


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------


An invalid character was found in text content. Error processing resource 'http://softwarecommunity.intel.com/isn/Community...

Imagen de Steve Lionel (Intel)

Worked ok for me just now. If you still have a problem, let me know.

Steve
Imagen de vivekrao4@yahoo.com

I am able to download the zip file using Firefox at work and at home but am not able to download it using Internet Explorer 6.0.2900 at work, running Windows XP Pro. My problem is solved, anyway. Thanks.


Vivek Rao


Imagen de dan_trowbridge

Steve,
I am trying to build a mixed language (c++ & FORTRAN) code that I had working about a year ago with a previous version of Intel's FORTRAN compiler (v8 I think). ( I am now using Visual Studio 2003 and Intel's FORTRAN 10.1.011). I build a FORTRAN dll and call it from c++. I can get the code to build but I get a run-time error (pop-up window) that says "The procedure entry point __cpowq could not be located in the dynamic link library libmmd.dll". So I tried to run your sample C_calls_Fortran. Visual studio had to converted the solution and projects to V10. All projects compiled fine but when I run the USEDLL code I get the same error as I get with my code. Is something wrong with my install? Did something in the projects not get converted correctly.

I looked in the "libmmd.lib" file and I find what looks like a reference to "___cpowq". The case matches but it looks like it has an extra leading underscore. Any help would be greatly appreciated.

Thanks
Dan

Imagen de dan_trowbridge

Steve,

Never mind, I found the problem. It so happens that Roxio (the CD burning code) had in its distribution a library by the same name and its directory appeared earlier in the search path than the FORTRAN compiler's library. I still don't get the triple undersore thing but since the code is working I guess I am not going to worry about it. (I also noticed some versions of routines in the .lib file that had a "_imp_" prepended to the name. I guess these are some kind of naming conventions.)

Bottom line is that is was a problem in finding the right library and it is now fixed.

Thanks anyway.
Dan

Imagen de Steve Lionel (Intel)

__imp_ means that the symbol is imported from a DLL's import library.

Steve
Imagen de Svein-Atle Engeseth

Hi,
I tried to run the FXPLORER sample. Compilation went well, but when I started the program the message can't find IFDLGnnn.DLL appeared. I searched for such files and found one, IFDLG100.DLL, located in the compiler's bin directory. I use version 10.1.011 of the compiler. Any idea of how to solve this?
SAE

Imagen de Steve Lionel (Intel)

Argh. Copy that DLL into the compiler's LIB folder. It is supposed to be in both but it isn't. I'll get that fixed.

Steve
Imagen de Svein-Atle Engeseth

Hi Steve,
I have done as you said, but it still doesn't work. I rebuilt the solution, done in the IDE. The message is that the DLL is missing or not registered. Same as before. Does the ifort.cfg have anything to say in this? I don't use the original one.
SAE

Imagen de Steve Lionel (Intel)

Open a command prompt window, change directory (cd) to the compiler LIB folder, and type the command:

regsvr32 ifdlg100.dll

This will take care of it.

I have noticed that with this example, sometimes when the program closes an error message appears. I have not yet found the cause of this.

Steve
Imagen de PeterTheRascal

Re: IVF StdCall DLLs Fortran- Excel/VBA/VB with Strings IN, OUT and INOUT

I have had trouble upgrading old CVF style code to IVF. The modern IVF  multi-language (...11.0\066\fortran\Samples\Fortran\MixedLanguage\..) sample does not offer both IN and  OUT strings.   Can anyone show me reliable samples of stdcall DLLs  Fortran- Excel/VB/VBA  which do.

erratum (28-Mar)  as with cvf: "You can use CHARACTER(LEN=*) in Fortran if you omit the REFERENCE attribute and in the VB code,' explicitly pass a length (perhaps using the LEN intrinsic) as a "ByVal arglen as Long" argument' immediately following the string argument".  But my strings are not passing properly in IVF.

. I use: Intel(R) Visual Fortran Composer XE 2013 Update 1 Integration for Microsoft Visual Studio* 2008, 13.0.3600.2008, Copyright (C) 2002-2012 Intel Corporatio

(as old CVF sample)

*******   Excel/ VBA  ******

Declare Sub DLL_ROUT Lib "Fcall.dll" ( _

ByRef INT_ARG As Long, _

ByVal STR_IN As String, ByVal STR_IN_LEN As Long, _

ByVal STR_OUT As String, ByVal STR_OUT_LEN As Long)

****  Fortran  ***

! Fortran part of a VB-Fortran DLL example. This

! routine DLL_ROUT is called from a VB executable

! program.

SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT)

IMPLICIT NONE

! Specify that DLL_ROUT is exported to a DLL

! and that the external name is 'DLL_ROUT'

!DEC$ ATTRIBUTES STDCALL, DLLEXPORT :: DLL_ROUT

!DEC$ ATTRIBUTES ALIAS:'DLL_ROUT' :: DLL_ROUT

! ** My own code has..

!!DEC$ATTRIBUTES REFERENCE  ::INT_ARG, STR_IN, STR_OUT 

INTEGER INT_ARG

CHARACTER(Len=*) STR_IN, STR_OUT

 ! This routine converts INT_ARG to a decimal string.

! appends the string value to STR_IN and stores it

! in STR_OUT.

!

! Note that there are implicit length arguments

! following the addresses of each CHARACTER argument.

 CHARACTER(Len=6) INT_STR 

WRITE (INT_STR,'(I5.5)')INT_ARG

STR_OUT = STR_IN // INT_STR

RETURN

END

 Many thanks

 

Imagen de Steve Lionel (Intel)

I'll take a look at this tomorrow.

Steve
Imagen de Sergey Kostrov

This is a short follow up regarding ...Warning C4996: 'strcpy' was declared deprecated...

For a long time Microsoft advises software developers to start using secure CRT-functions with _s suffix. For example, instead of strcpy a secure function strcpy_s needs to be used. A developer has a full control of these warnings and they could be disabled by defining _ATL_SECURE_NO_DEPRECATE or _AFX_SECURE_NO_DEPRECATE macros before including string.h or wchar.h header files.

Imagen de Steve Lionel (Intel)

Peter, I am confused as to what you want. The VB sample you quote already does output strings. The current C_Calls_Fortran sample isn't yet using BIND(C) - I will remedy that for a future release - but it uses LEN=*. What are you looking for?

Steve
Imagen de PeterTheRascal

Hi Steve

My apologies forthe confusion. The Len=* is a redherring. But the code, which I believe would work in CVF, fails to,pass the arrays to Fortran. The excel can now test both with (1) worksheet function (2) command button. Though the code has issues.. The fcall3.xls is in debug directory.

29-Mar-13:  I would be pleased to have a choice between LEN=* and LEN=len (not shown) versions. But neither are working

Thanks Peter

Adjuntos: 

AdjuntoTamaño
Descargar fcall3.zip882.71 KB
Imagen de Steve Lionel (Intel)

The fcall3.xls doesn't seem (to my non-Excel-experienced) eye to have the VBA code to call the DLL. You have several XLS files there. I am used to being able to press Alt-F11 to bring up the VBA editor, but that does nothing in your fcall3.xls.

Steve
Imagen de PeterTheRascal

Steve: Here is a new version with 

Two DLL methods

  1. Much as old CVF (LEN=* etc) this fails. It would be nice to fix this but, if necessary perhaps option 2 will suffice?
  2. Based on modern example (Len=<big enough> etc) . This now works

Two methods of running in excel (fcall6.xls)

  1. as cell formula  (Instructions in the spreadsheet!)
  2. via a command button (recomended)

Is there a way to only receive Forum emails automatically on "ones own" questions? Or could you possibly email as well?Many thanks Peter

Adjuntos: 

AdjuntoTamaño
Descargar fcall3.zip886.18 KB
Imagen de Steve Lionel (Intel)

You can click "Subscribe to this post" at the top of the topic and it will send you emails for all replies to that topic.

I will look at your new zip.

Steve
Imagen de Steve Lionel (Intel)

Ok, a couple of things going on with your FC_10 call. First, you declare the strings in Excel to be 20 bytes but declared them in Fortran to be 100. When you assigned to STR_OUT in DLL_ROUT10, this corrupted memory and resulted in an access violation.  Fix: declare STR_IN and STR_OUT as CHARACTER(20).

Second, you use INDEX to search for a trailing NUL to set LEN_IN and LEN_OUT. Excel doesn't use that convention, so get rid of those. Just use TRIM to trim trailing blanks.

When I do this, it works.

Steve
Imagen de PeterTheRascal

Steve

I should have said that rough and ready "OK" code ("specifield len=??" paradigm e.g. FC_10)   was prone to memery issues. But I had hoped there was a safe way of making the Forran strings "very big" to allow the same flexibiity as len=*

So if the len=* can be made to work in IVF that would certainly be great.   I guess there might be a third option ijn which the len arg is past through in a non-tranparent way

thanks, Peter

Imagen de Steve Lionel (Intel)

No, there isn't unless you go the "BSTR" route which is more complicated. One of the VB examples demonstrates this. I think it would be easier to pass the lengths.

Steve
Imagen de PeterTheRascal

Hi Steve

Re the char(LEN=*) Sample DLL in Excel in modern IVF

To avoid BSTR we discussed  two options but I am stuck on both

1) Character(len=*): not working  2) Character(len=X): I have had no luck

Can you please demonstate one working one? 

Pter

Imagen de FortranFan

Hi Steve,

The link you provided for samples in your original posting on this thread appears to be broken.

Thanks, 

Imagen de Steve Lionel (Intel)

LEN=* will work if your Excel code passes the character variable lengths by value. LEN=x will work if x is the same as the VBA declaration (and you specify REFERENCE for the procedure and arguments.

Please ignore the link - it is from 2005 before we started including samples in the product.

I suggest that you start a new thread on your question rather than tacking it on to this ancient one.

Steve

Inicie sesión para dejar un comentario.