<?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[Kein Klassen-Template aber eine Template-Methode ...]]></title><description><![CDATA[<p>Hallo,</p>
<p>Es geht im speziellen um die Methode GetFunctionPtr.<br />
Fehler:<br />
PUmGetUserCount&quot; : Ungültige Verwendung dieses Typs als Ausdruck</p>
<p>Lt. Funktions-Template sollte das so rcihtig sein, nur bin ich mir nicht<br />
sicher ob das auch so für Methoden richtig ist.<br />
Der Fehler hat erstmal ja nix damit zu tun. Ist aber mein aktuelle Problem.</p>
<p>Eine Funktion wie:</p>
<pre><code class="language-cpp">template&lt; class T &gt; T LoadFunction(HINSTANCE hLib, char* function_name, T*
pfn)
{
 *pfn = NULL;
 if( NULL == (*pfn=(T)GetProcAddress(hLib, function_name)) )
 {
  string strErr;
  strErr.append(&quot;Funktion: &quot;);
  strErr.append(function_name);
  strErr.append(&quot; nicht in DLL vorhanden&quot;);
  throw(strErr);
 }
 return *pfn;
}
funktioniert mit:
LoadFunction(m_hLib_Userdata, &quot;UmGetUserCount&quot;, &amp;pUmGetUserCount);
&quot;komischer&quot; Weise ... obwohl keine weitere spezifikation des Typs angegeben
wurde ???

Besten Dank für Eure Hilfe.
Grüße
RB

typedef short (*PUmGetUserCount)(void);
void test()
{
 PUmGetUserCount pUmGetUserCount;
 CDll dll(&quot;test.dll&quot;);
 dll.GetFunctionPtr&lt;PUmGetUserCount&gt;(&quot;UmGetUserCount&quot;, &amp;pUmGetUserCount);
}

class CDll
{
public:
 CDll();
 CDll(string strDllName);
 virtual ~CDll();
 DWORD Load(string strDllName);
 DWORD Unload();
 template&lt;class T &gt; T GetFunctionPtr(const string function_name, T* pfn);

protected:
 HINSTANCE m_hLib;
};

CDll::CDll()
{
 HINSTANCE m_hLib = NULL;
}
CDll::CDll(string strDllName)
{
 Load(strDllName);
}
CDll::~CDll()
{
 Unload();
}
DWORD CDll::Load(string strDllName)
{
 Unload();

 SetLastError(0);
 if( NULL==(m_hLib=LoadLibrary(strDllName.c_str())) )
 {
  strDllName.append(&quot; kann nicht geladen werden&quot;);
  throw( new CDllException(GetLastError(), strDllName) );
 }
 return GetLastError();
}
DWORD CDll::Unload()
{
 SetLastError(0);
 if( m_hLib )
  FreeLibrary(m_hLib);
 m_hLib = NULL;
 return GetLastError();
}
template&lt;class T &gt; T CDll::GetFunctionPtr(const string function_name, T*
pfn)
{
 *pfn = NULL;
 SetLastError(0);
 if( NULL == (*pfn=(T)GetProcAddress(m_hLib, function_name)) )
 {
  string strErr;
  strErr.append(&quot;Funktion: &quot;);
  strErr.append(function_name);
  strErr.append(&quot; nicht in DLL vorhanden&quot;);
  throw( new CDllException(GetLastError(), strErr) );
 }
 return *pfn;
}
</code></pre>
<p>&lt;edit&gt;Bitte Code-Tags verwenden!&lt;/edit&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/134651/kein-klassen-template-aber-eine-template-methode</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 20:25:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/134651.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Jan 2006 14:36:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kein Klassen-Template aber eine Template-Methode ... on Mon, 30 Jan 2006 14:06:23 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Es geht im speziellen um die Methode GetFunctionPtr.<br />
Fehler:<br />
PUmGetUserCount&quot; : Ungültige Verwendung dieses Typs als Ausdruck</p>
<p>Lt. Funktions-Template sollte das so rcihtig sein, nur bin ich mir nicht<br />
sicher ob das auch so für Methoden richtig ist.<br />
Der Fehler hat erstmal ja nix damit zu tun. Ist aber mein aktuelle Problem.</p>
<p>Eine Funktion wie:</p>
<pre><code class="language-cpp">template&lt; class T &gt; T LoadFunction(HINSTANCE hLib, char* function_name, T*
pfn)
{
 *pfn = NULL;
 if( NULL == (*pfn=(T)GetProcAddress(hLib, function_name)) )
 {
  string strErr;
  strErr.append(&quot;Funktion: &quot;);
  strErr.append(function_name);
  strErr.append(&quot; nicht in DLL vorhanden&quot;);
  throw(strErr);
 }
 return *pfn;
}
funktioniert mit:
LoadFunction(m_hLib_Userdata, &quot;UmGetUserCount&quot;, &amp;pUmGetUserCount);
&quot;komischer&quot; Weise ... obwohl keine weitere spezifikation des Typs angegeben
wurde ???

Besten Dank für Eure Hilfe.
Grüße
RB

typedef short (*PUmGetUserCount)(void);
void test()
{
 PUmGetUserCount pUmGetUserCount;
 CDll dll(&quot;test.dll&quot;);
 dll.GetFunctionPtr&lt;PUmGetUserCount&gt;(&quot;UmGetUserCount&quot;, &amp;pUmGetUserCount);
}

class CDll
{
public:
 CDll();
 CDll(string strDllName);
 virtual ~CDll();
 DWORD Load(string strDllName);
 DWORD Unload();
 template&lt;class T &gt; T GetFunctionPtr(const string function_name, T* pfn);

protected:
 HINSTANCE m_hLib;
};

CDll::CDll()
{
 HINSTANCE m_hLib = NULL;
}
CDll::CDll(string strDllName)
{
 Load(strDllName);
}
CDll::~CDll()
{
 Unload();
}
DWORD CDll::Load(string strDllName)
{
 Unload();

 SetLastError(0);
 if( NULL==(m_hLib=LoadLibrary(strDllName.c_str())) )
 {
  strDllName.append(&quot; kann nicht geladen werden&quot;);
  throw( new CDllException(GetLastError(), strDllName) );
 }
 return GetLastError();
}
DWORD CDll::Unload()
{
 SetLastError(0);
 if( m_hLib )
  FreeLibrary(m_hLib);
 m_hLib = NULL;
 return GetLastError();
}
template&lt;class T &gt; T CDll::GetFunctionPtr(const string function_name, T*
pfn)
{
 *pfn = NULL;
 SetLastError(0);
 if( NULL == (*pfn=(T)GetProcAddress(m_hLib, function_name)) )
 {
  string strErr;
  strErr.append(&quot;Funktion: &quot;);
  strErr.append(function_name);
  strErr.append(&quot; nicht in DLL vorhanden&quot;);
  throw( new CDllException(GetLastError(), strErr) );
 }
 return *pfn;
}
</code></pre>
<p>&lt;edit&gt;Bitte Code-Tags verwenden!&lt;/edit&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/978030</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/978030</guid><dc:creator><![CDATA[RED-BARON]]></dc:creator><pubDate>Mon, 30 Jan 2006 14:06:23 GMT</pubDate></item><item><title><![CDATA[Reply to Kein Klassen-Template aber eine Template-Methode ... on Mon, 30 Jan 2006 08:27:24 GMT]]></title><description><![CDATA[<p>1. cpp-Tags sind doch einer feine Sache <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>
<p>2. Bei Funktions- und Methodenaufrufen benötigst du die Typangaben nur, wenn du sie nicht implizit aus den Parametern bestimmen kannst</p>
<p>3. In welcher Zeile tritt denn der Fehler auf?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/980728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/980728</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 30 Jan 2006 08:27:24 GMT</pubDate></item></channel></rss>