<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Externe dll will nicht so recht]]></title><description><![CDATA[<p>Hallo ich versuche eine dll in mein Programm einzubinden, das sieht dann wie folgt aus:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &quot;AtUsbHid.h&quot;

using namespace std;

int main(int argc, char *argv[])
{
    HINSTANCE hLib = NULL;
    hLib =LoadLibrary(AT_USB_HID_DLL);
    if(hLib == NULL){
        cout &lt;&lt; &quot;boing\n&quot;;
    }
    loadFuncPointers(hLib);

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>und das ist die AtUsbHid.h:</p>
<pre><code class="language-cpp">#ifndef _ATUSBHID_H_
#define _ATUSBHID_H_

// Error codes.
#define ERROR_USB_DEVICE_NOT_FOUND          0xE0000001
#define ERROR_USB_DEVICE_NO_CAPABILITIES    0xE0000002

// name of the DLL to be loaded
#define AT_USB_HID_DLL &quot;AtUsbHid&quot;

// Implement the DLL export/import mechanism and allow a C-written program
// to use our DLL.
#ifdef ATUSBHID_EXPORTS
#define ATUSBHID_API extern &quot;C&quot; __declspec(dllexport)
#else
#define ATUSBHID_API extern &quot;C&quot; __declspec(dllimport)
#endif

// This macro function calls the C runtime's _beginthreadex function.
// The C runtime library doesn't want to have any reliance on Windows' data
// types such as HANDLE. This means that a Windows programmer needs to cast
// values when using _beginthreadex. Since this is terribly inconvenient,
// this macro has been created to perform the casting.
typedef unsigned(__stdcall *PTHREAD_START)(void *);

#define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
   pvParam, fdwCreate, pdwThreadId)                 \
      ((HANDLE)_beginthreadex(                      \
         (void *)        (psa),                     \
         (unsigned)      (cbStack),                 \
         (PTHREAD_START) (pfnStartAddr),            \
         (void *)        (pvParam),                 \
         (unsigned)      (fdwCreate),               \
(unsigned *)(pdwThreadId)))

// Allow applications not built with Microsoft Visual C++ to link with our DLL.
#define STDCALL __stdcall

// These macros make calling our DLL functions through pointers easier.
#define DECLARE_FUNCTION_POINTER(FUNC)  PF_##FUNC lp##FUNC=NULL;
#define LOAD_FUNCTION_POINTER(DLL,FUNC) lp##FUNC = (PF_##FUNC)GetProcAddress(DLL, #FUNC);
#define ADDR_CHECK(FUNC) if (lp##FUNC == NULL) {fprintf(stderr,&quot;%s\n&quot;, &quot;Error: Cannot get address of function.&quot;); return FALSE;}
#define DYNCALL(FUNC) lp##FUNC

///////////////////////////////////////////////////////////////////////////////
typedef BOOLEAN (STDCALL *PF_findHidDevice)(const UINT VendorID, const UINT ProductID);
typedef void    (STDCALL *PF_closeDevice)(void);
typedef BOOLEAN (STDCALL *PF_writeData)(UCHAR* buffer);
typedef BOOLEAN (STDCALL *PF_readData)(UCHAR* buffer);
typedef int     (STDCALL *PF_hidRegisterDeviceNotification)(HWND hWnd);
typedef void    (STDCALL *PF_hidUnregisterDeviceNotification)(HWND hWnd);
typedef int     (STDCALL *PF_isMyDeviceNotification)(DWORD dwData);
typedef BOOLEAN (STDCALL *PF_startBootLoader)(void);
typedef BOOLEAN (STDCALL *PF_setFeature)(UCHAR type,UCHAR direction, unsigned int length);
///////////////////////////////////////////////////////////////////////////////

// Exported functions prototypes.

///////////////////////////////////////////////////////////////////////////////
ATUSBHID_API BOOLEAN STDCALL findHidDevice(const UINT VendorID, const UINT ProductID);

//  Closes the USB device and all handles before exiting the application.
ATUSBHID_API void    STDCALL closeDevice(void);

ATUSBHID_API BOOLEAN STDCALL writeData(UCHAR* buf);

ATUSBHID_API BOOLEAN STDCALL readData(UCHAR* buffer);

ATUSBHID_API int     STDCALL hidRegisterDeviceNotification(HWND hWnd);

ATUSBHID_API void    STDCALL hidUnregisterDeviceNotification(HWND hWnd);

ATUSBHID_API int     STDCALL isMyDeviceNotification(DWORD dwData);

ATUSBHID_API BOOLEAN STDCALL setFeature(UCHAR type,UCHAR direction, unsigned int length);

///////////////////////////////////////////////////////////////////////////////

#ifndef ATUSBHID_EXPORTS

DECLARE_FUNCTION_POINTER(findHidDevice);
DECLARE_FUNCTION_POINTER(closeDevice);
DECLARE_FUNCTION_POINTER(writeData);
DECLARE_FUNCTION_POINTER(readData);
DECLARE_FUNCTION_POINTER(hidRegisterDeviceNotification);
DECLARE_FUNCTION_POINTER(hidUnregisterDeviceNotification);
DECLARE_FUNCTION_POINTER(isMyDeviceNotification);
DECLARE_FUNCTION_POINTER(setFeature);

// this function call all function available in the DLL *
static bool loadFuncPointers(HINSTANCE hLib)
{
    LOAD_FUNCTION_POINTER(hLib, findHidDevice);
    ADDR_CHECK(findHidDevice);

	LOAD_FUNCTION_POINTER(hLib, closeDevice);
    ADDR_CHECK(closeDevice);

	LOAD_FUNCTION_POINTER(hLib, writeData);
    ADDR_CHECK(writeData);

	LOAD_FUNCTION_POINTER(hLib, readData);
    ADDR_CHECK(readData);

	LOAD_FUNCTION_POINTER(hLib, hidRegisterDeviceNotification);
	ADDR_CHECK(hidRegisterDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, hidUnregisterDeviceNotification);
	ADDR_CHECK(hidUnregisterDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, isMyDeviceNotification);
	ADDR_CHECK(isMyDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, setFeature);
	ADDR_CHECK(setFeature);

    return true;
}

#endif

#endif  // _ATUSBHID_H_
</code></pre>
<p>Compiliert wird ohne Problem. beim laufen gibt es dann folgende Ausgabe:<br />
boing<br />
Error: Cannot get address of function.<br />
Kann mir da jemand weiterhelfen? Programmier erst wieder seit kurzen C++ und das bissche Wissen,was ich mal hatte, ist wieder total eingerostet. *nerv*</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/192398/externe-dll-will-nicht-so-recht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 00:32:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/192398.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Sep 2007 20:09:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Externe dll will nicht so recht on Thu, 13 Sep 2007 20:09:36 GMT]]></title><description><![CDATA[<p>Hallo ich versuche eine dll in mein Programm einzubinden, das sieht dann wie folgt aus:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &quot;AtUsbHid.h&quot;

using namespace std;

int main(int argc, char *argv[])
{
    HINSTANCE hLib = NULL;
    hLib =LoadLibrary(AT_USB_HID_DLL);
    if(hLib == NULL){
        cout &lt;&lt; &quot;boing\n&quot;;
    }
    loadFuncPointers(hLib);

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>und das ist die AtUsbHid.h:</p>
<pre><code class="language-cpp">#ifndef _ATUSBHID_H_
#define _ATUSBHID_H_

// Error codes.
#define ERROR_USB_DEVICE_NOT_FOUND          0xE0000001
#define ERROR_USB_DEVICE_NO_CAPABILITIES    0xE0000002

// name of the DLL to be loaded
#define AT_USB_HID_DLL &quot;AtUsbHid&quot;

// Implement the DLL export/import mechanism and allow a C-written program
// to use our DLL.
#ifdef ATUSBHID_EXPORTS
#define ATUSBHID_API extern &quot;C&quot; __declspec(dllexport)
#else
#define ATUSBHID_API extern &quot;C&quot; __declspec(dllimport)
#endif

// This macro function calls the C runtime's _beginthreadex function.
// The C runtime library doesn't want to have any reliance on Windows' data
// types such as HANDLE. This means that a Windows programmer needs to cast
// values when using _beginthreadex. Since this is terribly inconvenient,
// this macro has been created to perform the casting.
typedef unsigned(__stdcall *PTHREAD_START)(void *);

#define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
   pvParam, fdwCreate, pdwThreadId)                 \
      ((HANDLE)_beginthreadex(                      \
         (void *)        (psa),                     \
         (unsigned)      (cbStack),                 \
         (PTHREAD_START) (pfnStartAddr),            \
         (void *)        (pvParam),                 \
         (unsigned)      (fdwCreate),               \
(unsigned *)(pdwThreadId)))

// Allow applications not built with Microsoft Visual C++ to link with our DLL.
#define STDCALL __stdcall

// These macros make calling our DLL functions through pointers easier.
#define DECLARE_FUNCTION_POINTER(FUNC)  PF_##FUNC lp##FUNC=NULL;
#define LOAD_FUNCTION_POINTER(DLL,FUNC) lp##FUNC = (PF_##FUNC)GetProcAddress(DLL, #FUNC);
#define ADDR_CHECK(FUNC) if (lp##FUNC == NULL) {fprintf(stderr,&quot;%s\n&quot;, &quot;Error: Cannot get address of function.&quot;); return FALSE;}
#define DYNCALL(FUNC) lp##FUNC

///////////////////////////////////////////////////////////////////////////////
typedef BOOLEAN (STDCALL *PF_findHidDevice)(const UINT VendorID, const UINT ProductID);
typedef void    (STDCALL *PF_closeDevice)(void);
typedef BOOLEAN (STDCALL *PF_writeData)(UCHAR* buffer);
typedef BOOLEAN (STDCALL *PF_readData)(UCHAR* buffer);
typedef int     (STDCALL *PF_hidRegisterDeviceNotification)(HWND hWnd);
typedef void    (STDCALL *PF_hidUnregisterDeviceNotification)(HWND hWnd);
typedef int     (STDCALL *PF_isMyDeviceNotification)(DWORD dwData);
typedef BOOLEAN (STDCALL *PF_startBootLoader)(void);
typedef BOOLEAN (STDCALL *PF_setFeature)(UCHAR type,UCHAR direction, unsigned int length);
///////////////////////////////////////////////////////////////////////////////

// Exported functions prototypes.

///////////////////////////////////////////////////////////////////////////////
ATUSBHID_API BOOLEAN STDCALL findHidDevice(const UINT VendorID, const UINT ProductID);

//  Closes the USB device and all handles before exiting the application.
ATUSBHID_API void    STDCALL closeDevice(void);

ATUSBHID_API BOOLEAN STDCALL writeData(UCHAR* buf);

ATUSBHID_API BOOLEAN STDCALL readData(UCHAR* buffer);

ATUSBHID_API int     STDCALL hidRegisterDeviceNotification(HWND hWnd);

ATUSBHID_API void    STDCALL hidUnregisterDeviceNotification(HWND hWnd);

ATUSBHID_API int     STDCALL isMyDeviceNotification(DWORD dwData);

ATUSBHID_API BOOLEAN STDCALL setFeature(UCHAR type,UCHAR direction, unsigned int length);

///////////////////////////////////////////////////////////////////////////////

#ifndef ATUSBHID_EXPORTS

DECLARE_FUNCTION_POINTER(findHidDevice);
DECLARE_FUNCTION_POINTER(closeDevice);
DECLARE_FUNCTION_POINTER(writeData);
DECLARE_FUNCTION_POINTER(readData);
DECLARE_FUNCTION_POINTER(hidRegisterDeviceNotification);
DECLARE_FUNCTION_POINTER(hidUnregisterDeviceNotification);
DECLARE_FUNCTION_POINTER(isMyDeviceNotification);
DECLARE_FUNCTION_POINTER(setFeature);

// this function call all function available in the DLL *
static bool loadFuncPointers(HINSTANCE hLib)
{
    LOAD_FUNCTION_POINTER(hLib, findHidDevice);
    ADDR_CHECK(findHidDevice);

	LOAD_FUNCTION_POINTER(hLib, closeDevice);
    ADDR_CHECK(closeDevice);

	LOAD_FUNCTION_POINTER(hLib, writeData);
    ADDR_CHECK(writeData);

	LOAD_FUNCTION_POINTER(hLib, readData);
    ADDR_CHECK(readData);

	LOAD_FUNCTION_POINTER(hLib, hidRegisterDeviceNotification);
	ADDR_CHECK(hidRegisterDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, hidUnregisterDeviceNotification);
	ADDR_CHECK(hidUnregisterDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, isMyDeviceNotification);
	ADDR_CHECK(isMyDeviceNotification);

	LOAD_FUNCTION_POINTER(hLib, setFeature);
	ADDR_CHECK(setFeature);

    return true;
}

#endif

#endif  // _ATUSBHID_H_
</code></pre>
<p>Compiliert wird ohne Problem. beim laufen gibt es dann folgende Ausgabe:<br />
boing<br />
Error: Cannot get address of function.<br />
Kann mir da jemand weiterhelfen? Programmier erst wieder seit kurzen C++ und das bissche Wissen,was ich mal hatte, ist wieder total eingerostet. *nerv*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1364899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1364899</guid><dc:creator><![CDATA[Dija]]></dc:creator><pubDate>Thu, 13 Sep 2007 20:09:36 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Fri, 14 Sep 2007 06:47:31 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>bei</p>
<pre><code class="language-cpp">// name of the DLL to be loaded
#define AT_USB_HID_DLL &quot;AtUsbHid.dll&quot; // &lt;- .dll nicht vergessen
</code></pre>
<p>Und du solltest sicherstellen, dass die Datei auch tatsächlich so heißt.</p>
<p>gruß<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365012</guid><dc:creator><![CDATA[mad_martin]]></dc:creator><pubDate>Fri, 14 Sep 2007 06:47:31 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Fri, 14 Sep 2007 09:00:02 GMT]]></title><description><![CDATA[<p>Is eine Header-Datei von Atmel. Deswegen ollte ich dadrin nicht rumfuschen. Hat aber eh nichts geholfen. Geht auch so nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365078</guid><dc:creator><![CDATA[dija]]></dc:creator><pubDate>Fri, 14 Sep 2007 09:00:02 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Fri, 14 Sep 2007 09:41:46 GMT]]></title><description><![CDATA[<p>Wenn boing kommt hat Loadlibrary die dll nicht gefunden. Schreib da doch einfach mal den Namen (evtl samt Pfad) direkt rein. Dann sollte es gehen.<br />
Bei den vielen defines bekomme ich das kalte Grausen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365114</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 14 Sep 2007 09:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Fri, 14 Sep 2007 16:48:28 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-403.html" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365406</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Fri, 14 Sep 2007 16:48:28 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Sat, 15 Sep 2007 20:26:08 GMT]]></title><description><![CDATA[<p>Moin das war der entscheidende Tipp. Ich hatte es zwar schon vorher mit &quot;./AtUsbHid.dll&quot; versucht dabei aber nur die dll im Projekt- also Sourcecode-Ordner gehabt. Somit einmal in den Ordner mit der Binärdatei reinkopiert und es klappt.</p>
<p>Bezüglich der defines: Das is schon ziemlich schlimm, aber du solltes mal die Atmel Firmware für den Micocontroller sehen. Da wird hin und her definiert...GRAUSAM. Was die sich dabei wohl gedacht haben.</p>
<p>Bezüglich des Verschiebens; habs eigentlich ganz bewusst nicht in das WinApi-Forum gesetz, weil es ja keine Windows-Library ist, aber gut, wenn die Moderatoren meinen, es passt hier besser, ist mir das auch recht.</p>
<p>Besten Dank nochmal!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1366090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1366090</guid><dc:creator><![CDATA[DiJa]]></dc:creator><pubDate>Sat, 15 Sep 2007 20:26:08 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Sat, 15 Sep 2007 20:58:42 GMT]]></title><description><![CDATA[<p>Bzgl. WinAPI: Gibt es noch andere Platformen ausser Win32 wo eine *Windows-DLL* läuft!?<br />
Geschweige denn, wo es &quot;LoadLibrary&quot; gibt???</p>
<p>Also &quot;C++&quot; ist mit Sicherheit das falscheste Forum überhaupt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1366099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1366099</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sat, 15 Sep 2007 20:58:42 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Sun, 16 Sep 2007 09:40:32 GMT]]></title><description><![CDATA[<p>Nagut :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1366198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1366198</guid><dc:creator><![CDATA[Dija]]></dc:creator><pubDate>Sun, 16 Sep 2007 09:40:32 GMT</pubDate></item><item><title><![CDATA[Reply to Externe dll will nicht so recht on Sun, 16 Sep 2007 09:56:06 GMT]]></title><description><![CDATA[<p>Kannst ja mal schauen,<br />
vlt hilft dir Henkesoft's Dll-Programmiererung's Tutorial :</p>
<p><a href="http://www.henkessoft.de/C++/WinAPI/WinAPI%20Kapitel%201%20bis%206/api6.htm" rel="nofollow">http://www.henkessoft.de/C++/WinAPI/WinAPI Kapitel 1 bis 6/api6.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1366205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1366205</guid><dc:creator><![CDATA[pivke]]></dc:creator><pubDate>Sun, 16 Sep 2007 09:56:06 GMT</pubDate></item></channel></rss>