<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Lots of those files have a in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941797#M90217</link>
    <description>Lots of those files have a stray period in one of the directives after ATTRIBUTES and before ALIAS.  Be mindful that the debugger can sometimes fib about this sort of stuff.  I'll have a better look tomorrow, but bar that period I think things are working ok.

(What's up with the !@#$%^&amp;amp; forum??)</description>
    <pubDate>Tue, 30 Apr 2013 13:47:01 GMT</pubDate>
    <dc:creator>IanH</dc:creator>
    <dc:date>2013-04-30T13:47:01Z</dc:date>
    <item>
      <title>Character(LEN=*) Sample DLL in Excel in modern IVF</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941789#M90209</link>
      <description>&lt;P&gt;Hi Steve and others&lt;/P&gt;
&lt;P&gt;In &lt;A href="http://software.intel.com/en-us/forums/topic/275070"&gt;http://software.intel.com/en-us/forums/topic/275070&lt;/A&gt; &amp;nbsp;we discussed:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In IVF 11 (an 10) &amp;nbsp;I am trying unsuccefully to pass strings to and from excel (i.e.VBA=VB6) using in an stdcall DLL much as I in CVF using len=*.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My conclusion:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid BSTR we discussed&amp;nbsp; two options but I am stuck on both&lt;/P&gt;
&lt;P&gt;&amp;nbsp;1) Character(len=*): not working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2) Character(len=X): I have had no luck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Can you please demonstrate one working one? The attached zip is much as the one I sent many seeks ago on the other forum and allows one to test with either Buttons or cell formula.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2013 17:43:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941789#M90209</guid>
      <dc:creator>Peter_A_1</dc:creator>
      <dc:date>2013-04-24T17:43:13Z</dc:date>
    </item>
    <item>
      <title>I am not going to be able to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941790#M90210</link>
      <description>&lt;P&gt;I am not going to be able to look at this for a few weeks. The only way to get character(*) working is to send the length by value at the end of the argument list.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2013 18:01:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941790#M90210</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-04-24T18:01:20Z</dc:date>
    </item>
    <item>
      <title>I prefer to pass the length</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941791#M90211</link>
      <description>&lt;P&gt;I prefer to pass the length explicitly, because that &lt;EM&gt;may&lt;/EM&gt; avoid future changes in the binary interrface for passing strings (32 bit versus 64 bit, compiler options, etc).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(That's a pretend justification - really I prefer it because I can never remember what the binary interface (after the argument, after all arguments, etc) is, so I stick with what I know.)&lt;/P&gt;
&lt;P&gt;So, having a look at that case specifically - your DLL_ROUT20 case has got a reference (VBA code) versus value (Fortran code) mismatch for the string length arguments.&amp;nbsp; If you fix that (value probably makes more sense) I think you'd be ok.&lt;/P&gt;
&lt;P&gt;Note the length specification expression for the character dummy arguments uses variables that then have their type specified after the expression, in a scope that doesn't have implicit typing. That's an extension to the language.&amp;nbsp; Obviously the code uses other extensions (all that !DEC$ business) so maybe this point is a little silly, but I don't see much point in making the code more reliant on extensions than it needs to be, plus personally I find the "correct" ordering makes the code easier to follow.&lt;/P&gt;
&lt;P&gt;Some of the comments in the Fortran for the other cases don't make sense or are inconsistent (perhaps they are out of date).&lt;/P&gt;
&lt;P&gt;For what its worth, a simple example.&amp;nbsp; Note that you can put the procedure into a module - which can be handy if you want to do some testing from Fortran code.&lt;/P&gt;
&lt;P&gt;[fortran]MODULE PassAString&lt;BR /&gt;&amp;nbsp; IMPLICIT NONE&lt;BR /&gt;&amp;nbsp; INTEGER, PARAMETER :: vba_long = 4&lt;BR /&gt;CONTAINS&lt;BR /&gt;&amp;nbsp; ! Processes a string sent across from VBA.&lt;BR /&gt;&amp;nbsp; !&lt;BR /&gt;&amp;nbsp; ! Use the following VBA declaration:&lt;BR /&gt;&amp;nbsp; !&amp;nbsp;&amp;nbsp; Private Declare Sub FixedLength Lib "PassAString" _&lt;BR /&gt;&amp;nbsp; !&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ByVal str As String, ByVal str_len As Long)&lt;BR /&gt;&amp;nbsp; SUBROUTINE FixedLength(str, str_len)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; !DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: FixedLength&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; !DEC$ ATTRIBUTES ALIAS:'FixedLength' :: FixedLength&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! Procedure is STDCALL so this is passed by value by default.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER(vba_long), INTENT(IN) :: str_len&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! We want the address of the string, and don't want the hidden length &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! to be passed (because we are passing it explicitly).&amp;nbsp; REFERENCE &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! for the argument does both.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHARACTER(str_len), INTENT(INOUT) :: str&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; !DEC$ ATTRIBUTES REFERENCE :: str&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER :: i&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHARACTER(str_len) :: tmp&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; !****&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp = ''&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO i = 1, LEN_TRIM(str)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp(LEN_TRIM(str)+1-i:LEN_TRIM(str)+1-i) = str(i:i)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; END DO&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = tmp&lt;BR /&gt;&amp;nbsp; END SUBROUTINE FixedLength&lt;BR /&gt;END MODULE PassAString&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;And the VBA bit...&lt;/P&gt;
&lt;P&gt;[plain]Option Explicit&lt;BR /&gt;&lt;BR /&gt;' Declare our Fortran procedure.&lt;BR /&gt;Private Declare Sub FixedLength Lib "PassAString" _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ByVal str As String, ByVal str_len As Long)&lt;BR /&gt;&lt;BR /&gt;'*******************************************************************************&lt;BR /&gt;'&lt;BR /&gt;' Call our Fortran procedure.&lt;BR /&gt;'&lt;BR /&gt;' str [in]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The string to process.&lt;BR /&gt;'&lt;BR /&gt;' Returns whatever gets sent back from Fortran.&lt;BR /&gt;'&lt;BR /&gt;' str is byval because we modify it internally.&lt;BR /&gt;&lt;BR /&gt;Public Function WhateverYouWantToCallTheFunction(ByVal str As String) As String&lt;BR /&gt;&amp;nbsp; Call FixedLength(str, Len(str))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;WhateverYouWantToCallTheFunction = str&lt;BR /&gt;End Function&lt;BR /&gt;[/plain]&lt;/P&gt;
&lt;P&gt;While we are here, this little bit of VBA popped into the code sheet for the workbook can sometimes make working with Excel and Fortran DLL's a bit easier.&lt;/P&gt;
&lt;P&gt;[plain]Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ByVal lpFilename As String) As Long&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;Private Declare Function FreeLibrary Lib "kernel32" _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ByVal handle As Long) As Long&lt;BR /&gt;&lt;BR /&gt;' Handle to the our DLL - loaded when we're loaded, unloaded when&lt;BR /&gt;' we are closed.&amp;nbsp; We do this to allow some choice of which DLL gets loaded&lt;BR /&gt;' (can point to a debug version) - subsequent calls to&lt;BR /&gt;' LoadLibrary(dll_name) (which might be carried out behind our backs by&lt;BR /&gt;' VBA!) will just pull in the exact same DLL we load in our initialisation&lt;BR /&gt;' here.&lt;BR /&gt;Private hDll As Long&lt;BR /&gt;&lt;BR /&gt;Const dll_name As String = "PassAString.dll"&lt;BR /&gt;&lt;BR /&gt;'*******************************************************************************&lt;BR /&gt;'&lt;BR /&gt;' The workbook open event.&lt;BR /&gt;'&lt;BR /&gt;' Preloads the helper DLL, initially looking in the workbook's folder, the&lt;BR /&gt;' system's DLL search path and finally the Debug subdirectory of the workbook's&lt;BR /&gt;' folder.&lt;BR /&gt;&lt;BR /&gt;Private Sub Workbook_Open()&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; Dim sPath As String&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Workbook path.&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; '*****************************************************************************&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; ' Try the directory of this workbook&lt;BR /&gt;&amp;nbsp; sPath = ThisWorkbook.Path&lt;BR /&gt;&amp;nbsp; If (Right(sPath, 1) &amp;lt;&amp;gt; "\") Then sPath = sPath &amp;amp; "\"&lt;BR /&gt;&amp;nbsp; hDll = LoadLibrary(sPath &amp;amp; dll_name)&lt;BR /&gt;&amp;nbsp; If hDll &amp;lt;&amp;gt; 0 Then Exit Sub&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; ' Try the "normal" DLL locations - exe directory, the PATH, etc.&lt;BR /&gt;&amp;nbsp; hDll = LoadLibrary(dll_name)&lt;BR /&gt;&amp;nbsp; If hDll &amp;lt;&amp;gt; 0 Then Exit Sub&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; ' Perhaps we are doing development?&lt;BR /&gt;&amp;nbsp; hDll = LoadLibrary(sPath &amp;amp; "Debug\" &amp;amp; dll_name)&lt;BR /&gt;&amp;nbsp; If hDll &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print "Debug variant of " &amp;amp; dll_name &amp;amp; " loaded."&lt;BR /&gt;&amp;nbsp; Else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "Error: " &amp;amp; dll_name &amp;amp; " was not loaded"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;BR /&gt;&amp;nbsp; End If&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;'*******************************************************************************&lt;BR /&gt;'&lt;BR /&gt;' The workbook [before] close event.&lt;BR /&gt;'&lt;BR /&gt;' Calls FreeLibrary to offset the LoadLibrary and reduces the reference count&lt;BR /&gt;' for our helper DLL.&amp;nbsp; Depending on what VBA and Excel are doing the DLL may&lt;BR /&gt;' then be unloaded.&lt;BR /&gt;'&lt;BR /&gt;' (Sometimes it is handy just to execute this manually so that you can drop&lt;BR /&gt;' the DLL reference count to zero and allow it to be unloaded - perhaps because&lt;BR /&gt;' you want to rebuild the DLL without shutting down Excel, restarting Excel,&lt;BR /&gt;' reattaching the VS debugger, waiting 30 days for all the DLL symbols to load,&lt;BR /&gt;' etc.&amp;nbsp; In that case, comment out the hDll = 0 statement , and don't forget to&lt;BR /&gt;' manually run the _Open event when you are ready to start using the DLL&lt;BR /&gt;' again, or VBA will get very cross!)&lt;BR /&gt;&lt;BR /&gt;Private Sub Workbook_BeforeClose(cancel As Boolean)&lt;BR /&gt;&amp;nbsp; Dim api_result As Long&lt;BR /&gt;&amp;nbsp; If hDll &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; api_result = FreeLibrary(hDll)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hDll = 0&lt;BR /&gt;&amp;nbsp; End If&lt;BR /&gt;End Sub&lt;BR /&gt;[/plain]&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2013 03:14:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941791#M90211</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2013-04-25T03:14:55Z</dc:date>
    </item>
    <item>
      <title>There's no particular problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941792#M90212</link>
      <description>&lt;P&gt;There's no particular problem with using BSTRs.&amp;nbsp; Here are some utility functions which will put text into an Excel cell:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;!&amp;nbsp;&amp;nbsp; renamed from ConvertStringToBstr(), which has a linker conflict&lt;BR /&gt;INTEGER(INT_PTR_KIND()) FUNCTION StringToBSTR(string)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; USE OLEAUT32&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;USE IFNLS&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHARACTER*(*), INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; :: string&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER(INT_PTR_KIND()) bstr&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER*4 length&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER*2, ALLOCATABLE :: unistr(:)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;! First call to MBConvertMBToUnicode determines the length to allocate&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ALLOCATE (unistr(0))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;length = MBConvertMBToUnicode(string, unistr)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;DEALLOCATE (unistr)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;! Special case for all spaces&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (length &amp;lt; 0) THEN&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ALLOCATE (unistr(2))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;unistr(1) = #20&amp;nbsp;&amp;nbsp; &amp;nbsp;! Single space&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;unistr(2) = 0&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;! Null terminate&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ELSE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;! Second call to MBConvertMBToUnicode does the conversion&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ALLOCATE (unistr(length+1))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;length = MBConvertMBToUnicode(string, unistr)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;unistr(length+1) = 0&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;! Null terminate&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;END IF&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;bstr = SysAllocString(unistr)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;DEALLOCATE (unistr)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;StringToBSTR = bstr&lt;BR /&gt;END FUNCTION StringToBSTR&lt;BR /&gt;&lt;BR /&gt;INTEGER FUNCTION column_range (column, row1, row2) RESULT (range)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IMPLICIT NONE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHARACTER(LEN=*), INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: column&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER, INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: row1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER, INTENT(IN), OPTIONAL&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: row2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHARACTER(LEN=12)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: cell_id&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;TYPE(VARIANT)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: vBSTR1, vBSTR2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER*4&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: pBSTR1, pBSTR2&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;WRITE (cell_id, '(A,I6,A)') column, row1, CHAR(0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;pBSTR1 = leftpack (cell_id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CALL VariantInit (vBSTR1)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;vBSTR1%VT = VT_BSTR&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;pBSTR1 = StringToBSTR (cell_id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;vBSTR1%VU%PTR_VAL = pBSTR1&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (PRESENT(row2)) THEN&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;WRITE (cell_id, '(A,I6,A)') column, row1, CHAR(0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;pBSTR2 = leftpack (cell_id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;CALL VariantInit (vBSTR2)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;vBSTR2%VT = VT_BSTR&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;pBSTR2 = StringToBSTR (cell_id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;vBSTR2%VU%PTR_VAL = pBSTR2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;range = $Worksheet_GetRange (worksheet, vBSTR1, vBSTR2, $STATUS=status)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;status = VariantClear(vBSTR2)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (pBSTR2 /= 0) CALL SysFreeString (pBSTR2)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ELSE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;range = $Worksheet_GetRange (worksheet, vBSTR1, $STATUS=status)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;END IF&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;status = VariantClear(vBSTR1)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (pBSTR1 /= 0) CALL SysFreeString (pBSTR1)&lt;BR /&gt;END FUNCTION column_range&lt;BR /&gt;&lt;BR /&gt;SUBROUTINE PutTextInCell (column, row, string, width)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IMPLICIT NONE&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHARACTER(LEN=*), INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;:: column&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER, INTENT(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: row&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CHARACTER(LEN=*), INTENT(INOUT)&amp;nbsp;&amp;nbsp; &amp;nbsp;:: string&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER, INTENT(IN), OPTIONAL&amp;nbsp;&amp;nbsp; &amp;nbsp;:: width&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTEGER&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;:: range&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;range = column_range (column, row)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF (PRESENT(width))&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;status = AUTOSETPROPERTYINTEGER2 (range, "ColumnWidth", INT2(width))&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;CALL NullTerminateString (string)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;status = AUTOSETPROPERTYCHARACTER (range, "VALUE", string)&lt;BR /&gt;&lt;BR /&gt;END SUBROUTINE PutTextInCell&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2013 05:19:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941792#M90212</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2013-04-25T05:19:53Z</dc:date>
    </item>
    <item>
      <title>Many thanks to IanH an</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941793#M90213</link>
      <description>&lt;P&gt;Many thanks to IanH an PaulCurtis for the fast response.&lt;/P&gt;

&lt;P&gt;The old CVF example required negligble extra code and allows the same stdcall dll to be used my vba and in, say, Fortran, Mathematica and I assume Matlab etc. As you will know (it is also in my VBA, Sampes link etc):&lt;/P&gt;

&lt;P&gt;To pass a VB string, declare the argument as ByVal in the VB module. In the Fortran code,&lt;/P&gt;

&lt;P&gt;' specify ATTRIBUTES STDCALL explicitly for the Fortran routine and ATTRIBUTES REFERENCE explicitly&lt;BR /&gt;
	' for the CHARACTER argument, which must be declared with fixed length.&lt;/P&gt;

&lt;P&gt;I am happy to change to,adding length arguments and use whaever ByVal or ByRef that is necessary.&lt;/P&gt;

&lt;P&gt;Paul Curtis: &amp;nbsp;BSTR is, for now, far too complex. Especially as I really want one generiic DLL for VBA and other languages.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;IanH:ByVal did not seem enough to fix i tDLL_RLOUT20). In VBA the string is till "substring argumants out &amp;nbsp;of bounds" leading to an evential crash.&lt;/P&gt;

&lt;P&gt;So the question is: can we find a solution as simple as in CVF which, if necessary/ desired passes the strng length. And that talks to both VBA and is still a flexible stdcall DLL.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Peter&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2013 15:36:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941793#M90213</guid>
      <dc:creator>Peter_A_1</dc:creator>
      <dc:date>2013-04-27T15:36:00Z</dc:date>
    </item>
    <item>
      <title>My utility routine [bold</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941794#M90214</link>
      <description>&lt;P&gt;&lt;STRONG&gt;PutTextInCell(column, row, string)&lt;/STRONG&gt; exactly answers the original question, how to pass a string of indeterminate length LEN(*) to Excel.&lt;/P&gt;
&lt;P&gt;BSTRs are only used as intermediate data structures in the supporting routines, your Fortran code does not otherwise need to deal explicitly with this data type at all.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2013 18:21:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941794#M90214</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2013-04-27T18:21:00Z</dc:date>
    </item>
    <item>
      <title>Paul: My apologies if I was</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941795#M90215</link>
      <description>&lt;P&gt;Paul: My apologies if I was not clear.&lt;/P&gt;

&lt;P&gt;Ian:your&amp;nbsp;FixedLength does now work in my Excel so .. problem &amp;nbsp;solved (I assume).&lt;/P&gt;

&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2013 21:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941795#M90215</guid>
      <dc:creator>Peter_A_1</dc:creator>
      <dc:date>2013-04-27T21:04:00Z</dc:date>
    </item>
    <item>
      <title>Ian?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941796#M90216</link>
      <description>&lt;P&gt;Ian?&lt;/P&gt;

&lt;P&gt;While FixedLength works fine with Excel, &amp;nbsp;I very keen to have the same DLL useable elsewhere. &amp;nbsp;When calling (as a DLL) &amp;nbsp;from Intel Fortran, it does seem to work but debug Local shows STR has "Substring ouf Bounds". In Watch,&amp;nbsp;one can happily obsereve, say, str(1:30). I have even managed str, but most of the time ite is&amp;nbsp;&amp;nbsp;"Substring ouf Bounds".&lt;/P&gt;

&lt;P&gt;Thanks, Peter&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2013 09:19:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941796#M90216</guid>
      <dc:creator>Peter_A_1</dc:creator>
      <dc:date>2013-04-30T09:19:00Z</dc:date>
    </item>
    <item>
      <title>Lots of those files have a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941797#M90217</link>
      <description>Lots of those files have a stray period in one of the directives after ATTRIBUTES and before ALIAS.  Be mindful that the debugger can sometimes fib about this sort of stuff.  I'll have a better look tomorrow, but bar that period I think things are working ok.

(What's up with the !@#$%^&amp;amp; forum??)</description>
      <pubDate>Tue, 30 Apr 2013 13:47:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Character-LEN-Sample-DLL-in-Excel-in-modern-IVF/m-p/941797#M90217</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2013-04-30T13:47:01Z</dc:date>
    </item>
  </channel>
</rss>

