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

Discussion of Intel Visual Fortran samples

Steven_L_Intel1
Employee
2,772 Views

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

0 Kudos
35 Replies
Steven_L_Intel1
Employee
798 Views
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.
0 Kudos
Peter_A_1
Beginner
798 Views

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

 

0 Kudos
Steven_L_Intel1
Employee
798 Views

I'll take a look at this tomorrow.

0 Kudos
SergeyKostrov
Valued Contributor II
798 Views
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.
0 Kudos
Steven_L_Intel1
Employee
798 Views

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?

0 Kudos
Peter_A_1
Beginner
798 Views

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

0 Kudos
Steven_L_Intel1
Employee
798 Views

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.

0 Kudos
Peter_A_1
Beginner
798 Views

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

 

0 Kudos
Steven_L_Intel1
Employee
798 Views

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.

0 Kudos
Steven_L_Intel1
Employee
798 Views

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.

0 Kudos
Peter_A_1
Beginner
798 Views

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

0 Kudos
Steven_L_Intel1
Employee
798 Views

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.

0 Kudos
Peter_A_1
Beginner
798 Views

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

 

0 Kudos
FortranFan
Honored Contributor III
798 Views

Hi Steve,

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

Thanks, 

0 Kudos
Steven_L_Intel1
Employee
798 Views

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.

0 Kudos
Reply