<?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 The dll is called using in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055022#M116165</link>
    <description>&lt;P&gt;The dll is called using netlink in Mathematica.&lt;/P&gt;

&lt;P&gt;Here is the code:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;Needs["NETLink`"]

ReinstallNET["Force32Bit" -&amp;gt; True];

libName = "C:\\Users\\FrankM\\Documents\\Visual Studio\2012\\Projects\\G_Trend\\G_Trend\\Debug\\G_Trend.dll";

FileExistsQ[libName]

&amp;gt;True

TestSubroutine = DefineDLLFunction["G_Trend", libName, "void", {"int*", "Double[]", "Double[]"}]

&amp;gt;Function[Null,If[NETLink`DLL`Private`checkArgCount["G_Trend", {##1}, 3], Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper1`GUTrend[##1],$Failed], {HoldAll}]

Clear&lt;C&gt;;
Clear[date];
{date, c} = Transpose[FinancialData["GE", "Jan. 1, 2013"]];

pdlen = Length&lt;C&gt;;
fdata = MakeNETObject[Evaluate[Table[0.0, {pdlen}]]];

TestSubroutine[pdlen, c, fdata]

&amp;gt;NET::netexcptn: A .NET exception occurred: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.G_Trend(Int32&amp;amp; , Double[] , Double[] ).

$Failed

out = NETObjectToExpression[fdata];&lt;/C&gt;&lt;/C&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Given Repeat Offender's test (Thank You, I should have thought of that) the error must be in the calling.&lt;/P&gt;

&lt;P&gt;The above code worked for calling the dll G_Filter.&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;Needs["NETLink`"]

ReinstallNET["Force32Bit" -&amp;gt; True];(*or InstallNET["Force32Bit"\[Rule]True]*)

libName = "C:\\Users\\FrankM\\Documents\\Visual Studio\2012\\Projects\\G_Filter\\G_Filter\\Debug\\G_Filter.dll";

FileExistsQ[libName]

&amp;gt;True

TestSubroutine = DefineDLLFunction["G_Filter", libName, "void", {"int*", "int*", "int*", "Double[]", "Double[]"}]

&amp;gt;Function[Null,If[NETLink`DLL`Private`checkArgCount["G_Filter", {##1}, 5], Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper1`GUFilter[##1],$Failed], {HoldAll}]

Clear&lt;C&gt;;
Clear[date];
{date, c} = Transpose[FinancialData["IBM", "Jan. 1, 2013"]];

pdlen = Length&lt;C&gt;;
lag = 5;
push = 5;
pdata = c;
fdata = MakeNETObject[Evaluate[Table[0.0, {pdlen}]]];

TestSubroutine[pdlen, lag, push, pdata, fdata]

out = NETObjectToExpression[fdata];&lt;/C&gt;&lt;/C&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;There is a copy of G_Filter.dll in the G_Trend/Debug directory, so I would think windows would be able to find it.&lt;/P&gt;

&lt;P&gt;Thanks guys. I'll first study and run Repeat Offenders Test using the actual G_Filter, then look into that Dependency Walker.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Jan 2015 00:09:32 GMT</pubDate>
    <dc:creator>Frank_M</dc:creator>
    <dc:date>2015-01-26T00:09:32Z</dc:date>
    <item>
      <title>Calling a dll from a dll</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055016#M116159</link>
      <description>&lt;P&gt;&amp;nbsp;I need to break a library of functions into a number of separate dlls.&lt;/P&gt;

&lt;P&gt;How do I call a dll from within a dll?&lt;/P&gt;

&lt;P&gt;Can I do it within the same solution?&lt;/P&gt;

&lt;P&gt;Do I need to specify a library for the linker?&lt;/P&gt;

&lt;P&gt;Current attempt:&lt;/P&gt;

&lt;P&gt;!DEC$ ATTRIBUTES DLLEXPORT::G_Trend&lt;BR /&gt;
	!DEC$ ATTRIBUTES ALIAS:'G_Trend' :: G_Trend&lt;BR /&gt;
	!DEC$ ATTRIBUTES DLLIMPORT, ALIAS: 'G_Filter' ::G_Filter&lt;/P&gt;

&lt;P&gt;( blah, blah, blah)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;Call G_Filter(pdlen, lg, psh, lnc, tmp1)&lt;/P&gt;

&lt;P&gt;gives the error&lt;/P&gt;

&lt;P&gt;&amp;gt;G_Trend.obj : error LNK2019: unresolved external symbol __imp_G_Filter referenced in function G_Trend&lt;BR /&gt;
	2&amp;gt;Debug\G_Trend.dll : fatal error LNK1120: 1 unresolved externals&lt;/P&gt;

&lt;P&gt;The G_Filter function compiles and works great.( Tested by calling with netlink in mathematica)&lt;/P&gt;

&lt;P&gt;G_Filter and G_Trend are in different projects under the same solution.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Frank&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2015 06:13:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055016#M116159</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2015-01-19T06:13:34Z</dc:date>
    </item>
    <item>
      <title>the sample code "DLL" - file</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055017#M116160</link>
      <description>&lt;P&gt;the sample code "DLL" - file DynamicLoad.f90 - installed with the compiler may be helpful - it shows hows to load a DLL and access the functions in it.&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2015 06:27:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055017#M116160</guid>
      <dc:creator>DavidWhite</dc:creator>
      <dc:date>2015-01-19T06:27:00Z</dc:date>
    </item>
    <item>
      <title>There's no problem calling</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055018#M116161</link>
      <description>&lt;P&gt;There's no problem calling one DLL from another - it's done all the time. Assuming you want to resolve this at link time, just link the DLL to the export library of the other DLL(s), exactly as you would for linking an executable to DLLs.&lt;/P&gt;

&lt;P&gt;David's suggestion is a more complex approach for dynamic loading - it doesn't sound as if you need that.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:44:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055018#M116161</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-01-19T14:44:02Z</dc:date>
    </item>
    <item>
      <title> Thanks for the help.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055019#M116162</link>
      <description>&lt;P&gt;&amp;nbsp;Thanks for the help.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;I decided to try David's method first as it looks like it could be useful in the future.&lt;/P&gt;

&lt;P&gt;The current problem is that .net can't find the dll.&lt;/P&gt;

&lt;P&gt;The error message is "&amp;nbsp;A .NET exception occurred: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.G_Trend(Int32&amp;amp; , Double[] , Double[] )."&lt;/P&gt;

&lt;P&gt;I don't think the error is in the way I am call the dll.&lt;/P&gt;

&lt;P&gt;So what am I doing in this code that prevents it from being called?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;subroutine G_Trend(pdlen, pdata, acc)&lt;BR /&gt;
	use kernel32&amp;nbsp; ! Declares Windows API routines&lt;BR /&gt;
	use, intrinsic :: iso_c_binding&lt;/P&gt;

&lt;P&gt;IMPLICIT NONE&lt;BR /&gt;
	!DEC$ ATTRIBUTES DLLEXPORT::G_Trend&lt;BR /&gt;
	!DEC$ ATTRIBUTES ALIAS:'G_Trend' :: G_Trend&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; abstract interface&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subroutine G_Filter_void(pdlen0, lag0, lead0, pdata0, fdata0)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(4), 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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :: pdlen0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(4), 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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :: lag0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(4), 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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :: lead0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen0), intent(IN)&amp;nbsp;&amp;nbsp;&amp;nbsp; :: pdata0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen0), intent(INOUT) :: fdata0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end subroutine G_Filter_void&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; end interface&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure(G_Filter_void), pointer :: G_Filter&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INTPTR_T) :: p_G_Filter&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(HANDLE) :: dll_handle&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(BOOL) :: free_status&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(4), 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;&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; :: pdlen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen), intent(IN)&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :: pdata&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen), intent(INOUT) &amp;nbsp; :: acc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&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; :: lg, psh&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen)&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;&amp;nbsp;&amp;nbsp; :: lnc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen)&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; :: ldc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; real(8),&amp;nbsp;&amp;nbsp;&amp;nbsp; dimension(pdlen)&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; :: tmp1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dll_handle = LoadLibrary (lpLibFileName="G_Filter.dll"//C_NULL_CHAR)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; p_G_Filter = GetProcAddress (hModule=dll_handle, lpProcName="G_Filter"//C_NULL_CHAR)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; call C_F_PROCPOINTER (TRANSFER(p_G_Filter, C_NULL_FUNPTR), G_Filter)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; lnc = DLOG(pdata)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp1 = 0.0&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; acc = 0.0&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; lg = 1&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;&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;&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;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; psh = 0&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call G_Filter(pdlen, lg, psh, lnc, tmp1)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; free_status = FreeLibrary (hLibModule=dll_handle)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; return&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	end subroutine G_Trend&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Again, Thanks for the help. If I can't make this work, I'll try Steve's suggestion.&lt;/P&gt;

&lt;P&gt;Frank&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jan 2015 10:02:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055019#M116162</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2015-01-25T10:02:00Z</dc:date>
    </item>
    <item>
      <title>Your code looked fine to me,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055020#M116163</link>
      <description>&lt;P&gt;Your code looked fine to me, I added a G_Filter dll and a main program to invoke G_Trend and put in a couple of write statements to check that everything was going OK, and it all seemed to work. Output:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;&amp;nbsp;dll_handle =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 140729806094336
&amp;nbsp;GetLastError() =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0
&amp;nbsp;p_G_Filter =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 140729806098432
&amp;nbsp;GetLastError() =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0
&amp;nbsp;Called G_Filter&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jan 2015 16:16:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055020#M116163</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-01-25T16:16:18Z</dc:date>
    </item>
    <item>
      <title>Quote:Frank_M wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055021#M116164</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Frank_M wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;...&lt;/P&gt;

&lt;P&gt;The current problem is that .net can't find the dll.&lt;/P&gt;

&lt;P&gt;The error message is "&amp;nbsp;A .NET exception occurred: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.G_Trend(Int32&amp;amp; , Double[] , Double[] )."&lt;/P&gt;

&lt;P&gt;I don't think the error is in the way I am call the dll.&lt;/P&gt;

&lt;P&gt;So what am I doing in this code that prevents it from being called?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;...&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Can you show the relevant sections of your .NET code i.e., where you prototype the G_Trend procedure and where you call it?&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;Why do say, "The current problem is that .net can't find the dll"? &amp;nbsp;Have you confirmed you're getting a &amp;nbsp;zero value for the dll_handle in G_Trend? &amp;nbsp;If you think the execution is making it ok to G_trend and something is amiss therein, then here're s&lt;/SPAN&gt;ome suggestions:&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;Following your call to LoadLibrary procedure, you should check for the dll_handle return value and only proceed if it is not zero. &amp;nbsp;If it is zero, then it is confirmation the DLL was not found or it could not be loaded.&lt;/LI&gt;
	&lt;LI&gt;For the "not found" situation, check your PATH and ensure the DLL is indeed present in the path&lt;/LI&gt;
	&lt;LI&gt;For the "could not loaded" possibility, run your DLL through a dependency check utility such as DependencyWalker (www.dependencywalker.com) and see what other DLLs are required by the one in question and whether they are all available on the path.&lt;/LI&gt;
	&lt;LI&gt;If dll_handle is non-zero (usually greater than zero), then check&amp;nbsp;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;p_G_Filter return value from GetProcAddress and again only proceed to the next step if it is not zero. &amp;nbsp;If it is zero, then check whether the&amp;nbsp;G_Filter procedure is exported correctly from the DLL.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jan 2015 18:03:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055021#M116164</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2015-01-25T18:03:58Z</dc:date>
    </item>
    <item>
      <title>The dll is called using</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055022#M116165</link>
      <description>&lt;P&gt;The dll is called using netlink in Mathematica.&lt;/P&gt;

&lt;P&gt;Here is the code:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;Needs["NETLink`"]

ReinstallNET["Force32Bit" -&amp;gt; True];

libName = "C:\\Users\\FrankM\\Documents\\Visual Studio\2012\\Projects\\G_Trend\\G_Trend\\Debug\\G_Trend.dll";

FileExistsQ[libName]

&amp;gt;True

TestSubroutine = DefineDLLFunction["G_Trend", libName, "void", {"int*", "Double[]", "Double[]"}]

&amp;gt;Function[Null,If[NETLink`DLL`Private`checkArgCount["G_Trend", {##1}, 3], Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper1`GUTrend[##1],$Failed], {HoldAll}]

Clear&lt;C&gt;;
Clear[date];
{date, c} = Transpose[FinancialData["GE", "Jan. 1, 2013"]];

pdlen = Length&lt;C&gt;;
fdata = MakeNETObject[Evaluate[Table[0.0, {pdlen}]]];

TestSubroutine[pdlen, c, fdata]

&amp;gt;NET::netexcptn: A .NET exception occurred: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.G_Trend(Int32&amp;amp; , Double[] , Double[] ).

$Failed

out = NETObjectToExpression[fdata];&lt;/C&gt;&lt;/C&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Given Repeat Offender's test (Thank You, I should have thought of that) the error must be in the calling.&lt;/P&gt;

&lt;P&gt;The above code worked for calling the dll G_Filter.&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;Needs["NETLink`"]

ReinstallNET["Force32Bit" -&amp;gt; True];(*or InstallNET["Force32Bit"\[Rule]True]*)

libName = "C:\\Users\\FrankM\\Documents\\Visual Studio\2012\\Projects\\G_Filter\\G_Filter\\Debug\\G_Filter.dll";

FileExistsQ[libName]

&amp;gt;True

TestSubroutine = DefineDLLFunction["G_Filter", libName, "void", {"int*", "int*", "int*", "Double[]", "Double[]"}]

&amp;gt;Function[Null,If[NETLink`DLL`Private`checkArgCount["G_Filter", {##1}, 5], Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper1`GUFilter[##1],$Failed], {HoldAll}]

Clear&lt;C&gt;;
Clear[date];
{date, c} = Transpose[FinancialData["IBM", "Jan. 1, 2013"]];

pdlen = Length&lt;C&gt;;
lag = 5;
push = 5;
pdata = c;
fdata = MakeNETObject[Evaluate[Table[0.0, {pdlen}]]];

TestSubroutine[pdlen, lag, push, pdata, fdata]

out = NETObjectToExpression[fdata];&lt;/C&gt;&lt;/C&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;There is a copy of G_Filter.dll in the G_Trend/Debug directory, so I would think windows would be able to find it.&lt;/P&gt;

&lt;P&gt;Thanks guys. I'll first study and run Repeat Offenders Test using the actual G_Filter, then look into that Dependency Walker.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 00:09:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055022#M116165</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2015-01-26T00:09:32Z</dc:date>
    </item>
    <item>
      <title>Microsoft's .NET languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055023#M116166</link>
      <description>&lt;P&gt;Microsoft's .NET languages give a misleading "DLL not found" error when the problem is that a dependent DLL is not found. Dependency Walker is definitely helpful in this case.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 00:59:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055023#M116166</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-01-26T00:59:02Z</dc:date>
    </item>
    <item>
      <title>The interface to G_Filter in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055024#M116167</link>
      <description>&lt;P&gt;The interface to G_Filter in your Fortran example and that in your Mathematica example are inconsistent. In Mathematica you are forcing it to use a 32-bit dll (via ReinstallNET) where STDCALL is kind of an oddball calling convention which happens to be the default and then using this default in DefineDLLFunction. Your Fortran example doesn't specify a calling convention so unless a command-line switch is applied it won't be using STDCALL. I have modified&amp;nbsp;my example so it will refuse to compile in 64-bit mode and set up subroutine G_Trend and its interface in program P so that the STDCALL calling convention will be used. Output when compiled with 32-bit ifort was similar to that seen in Quote #5.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 02:46:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055024#M116167</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-01-26T02:46:46Z</dc:date>
    </item>
    <item>
      <title>Oh, and I should mention: if</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055025#M116168</link>
      <description>&lt;P&gt;Oh, and I should mention: if you are still having problems, do everything over exclusively in 64-bit mode so as to take STDCALL out of the equation. Once you get it running in 64-bit mode, then try to change over to 32-bit STDCALL. This will localize interfacing issues in smaller chunks.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2015 04:18:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055025#M116168</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-01-26T04:18:56Z</dc:date>
    </item>
    <item>
      <title>After including a console in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055026#M116169</link>
      <description>&lt;P&gt;After including a console in G_Trend and adding write statements, windows cannot find G_Filter.dll with the complete path specified.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!works
dll_handle = LoadLibrary (lpLibFileName="C:\Users\FrankM\Documents\Visual Studio 2012\Projects\G_Trend\G_Trend\Debug\G_Filter.dll"//C_NULL_CHAR)


!Fails
dll_handle = LoadLibrary (lpLibFileName="G_Filter.dll"//C_NULL_CHAR)&lt;/PRE&gt;

&lt;P&gt;Is there an elegant solution beyond hard code?&lt;/P&gt;

&lt;P&gt;In other news, Mathematica NetLink was not able to find G_Trend with Attribute set to StdCall or C. It likes the default unspecified C in 32bit.&lt;/P&gt;

&lt;P&gt;Once again, big thank you to everyone for all the help, especially Repeat Offender for the samples.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jan 2015 12:15:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055026#M116169</guid>
      <dc:creator>Frank_M</dc:creator>
      <dc:date>2015-01-28T12:15:00Z</dc:date>
    </item>
    <item>
      <title>Quote:Frank_M wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055027#M116170</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Frank_M wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;After including a console in G_Trend and adding write statements, windows cannot find G_Filter.dll with the complete path specified.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!works
dll_handle = LoadLibrary (lpLibFileName="C:\Users\FrankM\Documents\Visual Studio 2012\Projects\G_Trend\G_Trend\Debug\G_Filter.dll"//C_NULL_CHAR)


!Fails
dll_handle = LoadLibrary (lpLibFileName="G_Filter.dll"//C_NULL_CHAR)&lt;/PRE&gt;

&lt;P&gt;Is there an elegant solution beyond hard code?&lt;/P&gt;

&lt;P&gt;..&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;See&amp;nbsp;https://msdn.microsoft.com/en-us/library/7d83bc18.aspx for how Windows locates DLLs. &amp;nbsp;If there is a particular folder in Mathematica for "user" DLLs where you can place G_Filter.dll? &amp;nbsp;Or can you create a new folder for your DLLs and add it your PATH environment?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jan 2015 12:57:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-a-dll-from-a-dll/m-p/1055027#M116170</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2015-01-28T12:57:51Z</dc:date>
    </item>
  </channel>
</rss>

