<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Trebuchet MS";
panose-1:2 11 6 3 2 2 2 2 2 4;}
@font-face
{font-family:Webdings;
panose-1:5 3 1 2 1 5 9 6 7 3;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello everybody,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">today I faced the problem of interfacing TRNSYS with Types in external libraries. I run into difficulties which seemed caused by a misbehaviour of the dynamic loader in the TRNSYS kernel.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Solving the problem I found out that in the file Userlib.f90 one of the three calls to LoadLibrary() system function is not protected against the possible failure of the call (see lines 192-198 of the cited file, reported below).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7F0055">Do</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7F0055">While</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black"> (</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">bSt</span><span style="font-size:10.0pt;font-family:Consolas;color:black">)</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:#3F7F5F"> ! Get a pointer to the DLL that was just found and load all types</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">p</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> =
</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">LoadLibrary</span><span style="font-size:10.0pt;font-family:Consolas;color:black">(</span><i><span style="font-size:10.0pt;font-family:Consolas;color:#6000C0">TRIM</span></i><span style="font-size:10.0pt;font-family:Consolas;color:black">(</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">UserDir</span><span style="font-size:10.0pt;font-family:Consolas;color:black">)//</span><span style="font-size:10.0pt;font-family:Consolas;color:#2A00FF">"\\"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">//</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">WFD</span><span style="font-size:10.0pt;font-family:Consolas;color:black">%</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">cFileName</span><span style="font-size:10.0pt;font-family:Consolas;color:black">)</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7F0055">Call</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">LoadTypesFromDll</span><span style="font-size:10.0pt;font-family:Consolas;color:black">()</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">bSt</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> =
</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">FindNextFile</span><span style="font-size:10.0pt;font-family:Consolas;color:black">(</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">libFile</span><span style="font-size:10.0pt;font-family:Consolas;color:black">,</span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">WFD</span><span style="font-size:10.0pt;font-family:Consolas;color:black">)
</span><span style="font-size:10.0pt;font-family:Consolas;color:#3F7F5F">!returns FALSE if another dll is not found</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">LibCount</span><span style="font-size:10.0pt;font-family:Consolas;color:black">
= </span><span style="font-size:10.0pt;font-family:Consolas;color:#0000C0">LibCount</span><span style="font-size:10.0pt;font-family:Consolas;color:black">+1
</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><b><span style="font-size:10.0pt;font-family:Consolas;color:#7F0055">EndDo</span></b><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><span style="font-size:10.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The point is that the loading of a library may fail not only because the dll file of that library is not present in the UserLib/Release directory (which is detected by other means) but also, for example, because the library itself links
to another library that for whatever reason is not available. In this case (and that was exactly the case I run into), the messages printed by the kernel are deceiving as they maintain that the library has not been loaded because the type entry point has not
been found in the library.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Due to the wrong message, I wasted hours to figure out what was going on, using tools that even an above that average TRNSYS user is probably not aware of. Therefore I suggest to modify the code snippet above by making sure that the pointer
p is not NULL before calling LoadTypesFromDll() and printing a more informative message if this is the case. A simple “Failed to load library <FileName.dll>. Possible dependencies problem” is in my opinion much better than the message that is printed now.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sincerely,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">_ _</span><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">Anton Soppelsa, Ph.D.</span><span style="font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">EURAC research<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">Institute for Renewable Energy<br>
Via Luis-Zuegg 11, I-39100 Bolzano<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">t +39 0471 055 623<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">f +39 0471 055 699</span><span style="font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="DE" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:#1F497D;mso-fareast-language:EN-GB"><a href="mailto:davide.bettoni@eurac.edu"><span lang="EN-GB" style="color:blue">anton.soppelsa @eurac.edu</span></a></span><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><u><span lang="EN-US" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><a href="http://www.eurac.edu/"><span style="color:blue">www.eurac.edu</span></a></span></u><span lang="EN-US" style="font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">EURAC research<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IT" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">Legal Seat<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IT" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">Viale Druso 1, I-39100 Bolzano<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IT" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB">This transmission is intended only for the use of the addressee and may contain confidential or legally privileged information.
<br>
If you receive this transmission by error, please notify the author immediately by mail and delete all copies of this transmission and any attachments.
<br>
Any use or dissemination of this communication is strictly prohibited by the "Privacy-Code", D.Lgs. 196/2003 and may lead to penal prosecution and liability for damages.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Trebuchet MS","sans-serif";mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:20.0pt;font-family:Webdings;color:#00B050;mso-fareast-language:EN-GB">P</span><span style="font-size:10.0pt;color:#00B050;mso-fareast-language:EN-GB">
</span><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:#00B050;mso-fareast-language:EN-GB">Think before you print</span><span style="color:#00B050;mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>