<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — dll callable from VBA for EXCEL 2013]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=487</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=487&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in dll callable from VBA for EXCEL 2013.]]></description>
		<lastBuildDate>Wed, 26 Aug 2015 12:13:30 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: dll callable from VBA for EXCEL 2013]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2181#p2181</link>
			<description><![CDATA[<p>Charles,</p><p>The problem with calling a 32-bit Simply-Fortran-generated DLL from VBA normally centers around two issues:</p><ol class="decimal"><li><p>Calling convention</p></li><li><p>Function decorations</p></li></ol><p>For VBA to use a Fortran DLL (and make sure you&#039;ve built a 32-bit DLL, of course), the Fortran functions/subroutines must use the &quot;<a href="https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall">STDCALL</a>&quot; calling convention.&nbsp; To mark a routine as using this standard, you&#039;ll need to add the preprocessor directive to your Fortran code within your function/subroutine body:</p><div class="codebox"><pre><code>!GCC$ ATTRIBUTES STDCALL :: MyFunc</code></pre></div><p>Using the <a href="https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html#ISO_005fC_005fBINDING">ISO_C_BINDING</a> module is also recommended.&nbsp; When binding Fortran functions/subroutines as &quot;C&quot; callable, it can automatically configure how arguments are handled.</p><p>The decoration problem gets more complicated.&nbsp; Basically the STDCALL calling convention in Windows for DLLs expect functions within the DLL to appear as something like <em>MyFunc@4</em>.&nbsp; The Simply Fortran compiler will not generate this style of decoration, though.&nbsp; I usually suggest explicit use of <strong>DECLARE SUB</strong> statements in VBA to handle the mismatch of what VBA expects and what Simply Fortran DLLs provide.</p><p>If you want to see how your function is actually named in a DLL, you can inspect the symbols present in a DLL by opening it with Simply Fortran (using &quot;Open&quot; in the File menu).&nbsp; You&#039;ll receive a list of all symbols in the DLL in a relatively readable form.&nbsp; You can find your functions and subroutines by searching by name.&nbsp; By default, it might appear as &quot;myfunc_&quot; without any special compiler flags.</p><p><a href="http://forums.approximatrix.com/viewtopic.php?id=267">This thread covers a non-trivial example of how to call a Fortran DLL from VBA</a>.&nbsp; It should at least get you started in the right direction.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 26 Aug 2015 12:13:30 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2181#p2181</guid>
		</item>
		<item>
			<title><![CDATA[dll callable from VBA for EXCEL 2013]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2175#p2175</link>
			<description><![CDATA[<p>I am a new user of Simply Fortran. I have been programming with Fortran on and off for 40 years. I recently purchased Simply Fortran so I could convert a library of VBA functions and subroutines for EXCEL 2013 to a Fortran dll of callable functions and subroutines. These routines are part of a highly nonlinear thermodynamic model which sometimes takes up to 20 hours to execute. My hope is to dramatically reduce the execution time.</p><p>I am running a 32 bit version of EXCEL 2013 using 64 bit Windows 7 Professional running on a Dell Precision 6800 with an Intel Core i7-4800MQ CPU @ 2.70 MHz with 16 GB of ram.</p><p>So far, I have had no significant problems converting the VBA code to stand alone Fortran functions and subroutines. I have NOT had any luck in getting the generated dll to work with EXCEL. I have found very little on this topic for GNU Fortran. I have a lot of material on this subject for MS / Compaq / Digital / Intel Fortran. The examples for these versions of Fortran do not work for GNU Fortran. I suspect the problem is mostly related to not having the right compiler switches and or meta-commands in the GNU Fortran and VBA modules.</p><p>Any examples or guidance on how to properly call a GNU Fortran function or subroutine form VBA for EXCEL 2013 would be greatly appreciated.</p><p>Thanks, Charles</p>]]></description>
			<author><![CDATA[null@example.com (cchabannes)]]></author>
			<pubDate>Tue, 25 Aug 2015 18:46:40 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2175#p2175</guid>
		</item>
	</channel>
</rss>
