<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Aufruf von DLL-Funktionen unter WinCE 5.0</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/b0ef331744/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/b0ef331744/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Deutsch/thread/b0ef331744/</id><updated>2020-02-28T07:40:49.947000Z</updated><subtitle>Recent posts to Aufruf von DLL-Funktionen unter WinCE 5.0</subtitle><entry><title>Aufruf von DLL-Funktionen unter WinCE 5.0</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/b0ef331744/?limit=25#c22e" rel="alternate"/><published>2020-02-28T07:40:49.947000Z</published><updated>2020-02-28T07:40:49.947000Z</updated><author><name>RolandWagner</name><uri>https://forge.codesys.com/u/rowa/</uri></author><id>https://forge.codesys.com49894ea816f2dd81392926dca51c426c79cd776d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;ich habe eine &lt;strong&gt;nicht-offizielle Anleitung &lt;/strong&gt;dazu bekommen:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Zitat:&lt;/strong&gt;&lt;br/&gt;
The following instructions provide the detailed steps required to create an external DLL that provides functionality to the 3S CoDeSys SP soft PLC running under&lt;br/&gt;
Windows CE.&lt;br/&gt;
a) In Embedded Visual C++, use the new project wizard to create an empty DLL project &lt;br/&gt;
b) Create a C or C++ ++ source file for the primary interface functions&lt;br/&gt;
c) Add the function prototypes as defined by the .h file generated by&lt;br/&gt;
CoDeSys when you created the external library (copy from that file)&lt;br/&gt;
d) Ensure the types are correct&lt;br/&gt;
1.  Replace IEC data type ‘BOOL’  by ‘char’&lt;br/&gt;
2.  Replace IEC data type ‘INT’  by ‘short’&lt;br/&gt;
3.  Replace IEC data type ‘SINT’  by ‘signed char’&lt;br/&gt;
4.  Replace IEC data type ‘BOOL’  by ‘char’&lt;br/&gt;
5.  Replace IEC data type ‘BOOL’  by ‘char’&lt;br/&gt;
6.&lt;br/&gt;
e) Create a method that returns a pointer to each function based on a&lt;br/&gt;
provided name. This method is called by the runtime system to get a&lt;br/&gt;
function pointer to the actual implementation. The method must take the&lt;br/&gt;
following form:&lt;br/&gt;
f) Add your interface methods as required, conforming to the function&lt;br/&gt;
prototypes provided by the header file generated by CoDeSys.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;\#&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;__cplusplus&lt;/span&gt;
&lt;span class="nv"&gt;extern&lt;/span&gt; “&lt;span class="nv"&gt;C&lt;/span&gt;” {
\#&lt;span class="k"&gt;endif&lt;/span&gt;
&lt;span class="nv"&gt;_declspec&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dllexport&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;void&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;GetFunctionByName&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;functionName&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
{
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nv"&gt;determine&lt;/span&gt; &lt;span class="nv"&gt;which&lt;/span&gt; &lt;span class="nv"&gt;function&lt;/span&gt; &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;been&lt;/span&gt; &lt;span class="nv"&gt;requested&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;_stricmp&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;functionName&lt;/span&gt;, “&lt;span class="nv"&gt;Test&lt;/span&gt;”&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;address&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;desired&lt;/span&gt; &lt;span class="nv"&gt;function&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;Test&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nv"&gt;add&lt;/span&gt; &lt;span class="nv"&gt;other&lt;/span&gt; &lt;span class="nv"&gt;function&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="nv"&gt;tests&lt;/span&gt; &lt;span class="nv"&gt;here&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nv"&gt;no&lt;/span&gt; &lt;span class="nv"&gt;matching&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;, &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;NULL&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;NULL&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
}
\#&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;__cplusplus&lt;/span&gt;
}
\#&lt;span class="k"&gt;endif&lt;/span&gt;
&lt;span class="nv"&gt;char&lt;/span&gt; &lt;span class="nv"&gt;Test&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;char&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;, &lt;span class="nv"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
{
&lt;span class="nv"&gt;TCHAR&lt;/span&gt; &lt;span class="nv"&gt;str&lt;/span&gt;[&lt;span class="mi"&gt;80&lt;/span&gt;]&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;sprintf&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;str&lt;/span&gt;, “&lt;span class="nv"&gt;Function&lt;/span&gt; &lt;span class="nv"&gt;Test&lt;/span&gt; &lt;span class="nv"&gt;Called&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;Parameter&lt;/span&gt;: &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;, &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="nv"&gt;d&lt;/span&gt;”, &lt;span class="nv"&gt;text&lt;/span&gt;, &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;MessageBox&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;NULL&lt;/span&gt;, &lt;span class="nv"&gt;str&lt;/span&gt;, &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;LPCSTR&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;””, &lt;span class="nv"&gt;MB_ICONEXCLAMATION&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;MB_OK&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;3) Compile your source code into a DLL, perhaps named TestLib.dll, but the name is&lt;br/&gt;
not critical.&lt;br/&gt;
4) Copy your DLL into the C:\Windows\System32 directory so the system can find&lt;br/&gt;
it.&lt;br/&gt;
5) Add entries to the windows registry to indicate that the runtime system should&lt;br/&gt;
load the additional DLL. Set the “Path” entry to the name of your DLL file.&lt;br/&gt;
6) If the runtime system is currently running, stop and shutdown the runtime system&lt;br/&gt;
and restart it to ensure the new DLL is included.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys SP\PLC\External Dlls]&lt;/span&gt;
&lt;span class="na"&gt;"CheckExtRef"&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Yes"&lt;/span&gt;
&lt;span class="k"&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys SP\PLC\External Dlls\.0]&lt;/span&gt;
&lt;span class="na"&gt;"Path"&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"TestLib"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;7) Returning to the CoDeSys programming environment, create a new project that&lt;br/&gt;
will utilize the new function.&lt;br/&gt;
 In the new project, insert the previously created library:&lt;br/&gt;
a) Select Window-&amp;gt;Library Manager&lt;br/&gt;
b) Select Insert-&amp;gt;Additional Library&lt;br/&gt;
c) In the presented File Chooser, navigate to the library file (TestLib.lib)&lt;br/&gt;
created by CoDeSys when you exported your function definition as an&lt;br/&gt;
external library. It will be someplace similar to:&lt;br/&gt;
C:\Program Files\3S Software\CoDeSys V2.3\Library&lt;br/&gt;
d) Double click the file to load the library into the project. The library will be&lt;br/&gt;
shown in the Library Manager window, and the defined function should be&lt;br/&gt;
available.&lt;br/&gt;
9) Create a test program to invoke the external library function:&lt;br/&gt;
a) Create a new program unit, using the default name PLC_PRG.&lt;br/&gt;
b) Add a structured text (ST) program to the program unit, calling the&lt;br/&gt;
external function.&lt;br/&gt;
10) Test your new program:&lt;br/&gt;
a) Ensure the runtime system is active.&lt;br/&gt;
b) Create a new connection to the runtime system (if required)&lt;br/&gt;
c) “Login” to the runtime system.&lt;br/&gt;
d) When asked if the program should be downloaded, respond yes.&lt;br/&gt;
e) The program should be successfully downloaded.&lt;br/&gt;
f) Execute the program.&lt;br/&gt;
g) The desired behavior should be observed.&lt;br/&gt;
11) Celebrate!&lt;/p&gt;
&lt;p&gt;Wie gesagt: Das ist nicht-offiziell. Aber Du kannst ja hier kommentieren, ob und wie es geklappt hat. &lt;br/&gt;
In jedem Fall hänge ich noch ein Beispiel an.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Aufruf von DLL-Funktionen unter WinCE 5.0</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/b0ef331744/?limit=25#c46c" rel="alternate"/><published>2020-02-28T07:40:47.314000Z</published><updated>2020-02-28T07:40:47.314000Z</updated><author><name>uloebich</name><uri>https://forge.codesys.com/u/uloebich/</uri></author><id>https://forge.codesys.com517eced5c731e1caf350c75cc49c0041dae28490</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ich suche eine Möglichkeit, die Funktionen einer Drittanbieter-DLL unter WinCE 5.0 Core anzusprechen.&lt;br/&gt;
Geht das mit CoDeSys 2.3 und wenn ja, wie?&lt;/p&gt;
&lt;p&gt;Gruß, U.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>