<?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[GUID während Compile erstellen und zuordnen]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Visual C++ Projekt, in dem ich einen COM server implementiere. Dies klappt einwandfrei, solange ich die GUIDs für die Objekte direkt mit einem Generator erstellen lasse und fest in die Quelldatei eintrage. Nun will ich dies allerdings während des Compile automatisch generieren lassen und den Objekten zuordnen. Dies ist irgendwie etwas schwierig, da die GUIDs im .idl file eingetragen sind und dieses keine globalen Variablen aus den c-Dateien nimmt...<br />
Hier mein .idl file:</p>
<pre><code class="language-cpp">import &quot;oaidl.idl&quot;;
import &quot;ocidl.idl&quot;;
import &quot;guid.h&quot;;

// define the ICommunication interface
[object, uuid(guid),
 oleautomation, helpstring(&quot;Handles the communication&quot;)]
interface ICommunication : IUnknown
{
	HRESULT GetDataInBSTR([out, retval] BSTR* pBstr);

};

// library statement
[uuid(guid), version(1.0),
 helpstring(&quot;Local server with typeLib&quot;)]
library LocalServerTypeInfo
{
   importlib(stdole32.tlb);
   [uuid(guid)]
   coclass LocalServer
   {
      [default] interface ICommunication;
   };
};
</code></pre>
<p>Hier mein C file zur Generierung der GUIDs:</p>
<pre><code class="language-cpp">#include &lt;Rpcdce.h&gt; // für GUID-Funktionen
#include &lt;string.h&gt; // für String-Funktionen
#include &lt;guid.h&gt;

#pragma comment(lib, &quot;Rpcrt4.lib&quot;) // Rpcrt4.lib einbinden (GUID-Funktionen) 

void fguid()

{

    unsigned char    *StringUuid ; // Zeiger für die Umwandlung 
    HKEY            hKeyReg ; // Registrykey 
    TCHAR           szKey[MAX_PATH] = &quot;SOFTWARE\\Euklid\\Services\\&quot;; // Schluessel-Path 

     // guid auf 0 setzen 
    memset (&amp;guid, '\0', sizeof (guid)) ; 
    // neuen class GUID erstellen 
    if (CoCreateGuid (&amp;guid) == S_OK){ 
        if (UuidToString (&amp;guid, &amp;StringUuid) == RPC_S_OK)
		{ // GUID in &quot;unsigned char&quot; formatieren 
            strcpy (szGuid_class, &quot;{&quot;) ; 
            strcat (szGuid_class, (char*) StringUuid) ; 
            strcat (szGuid_class, &quot;}&quot;) ; 
            RpcStringFree (&amp;StringUuid) ; 
        } 
        else
		{ 
            MessageBox (NULL, &quot;Fehler in GUID-Erstellung.&quot;, &quot;:(&quot;, MB_ICONERROR) ; 
            return 0 ; 
        } 
    } 
    else
	{ 
        MessageBox (NULL, &quot;Fehler in GUID-Erstellung&quot;, &quot;:(&quot;, MB_ICONERROR) ; 
        return 0 ; 
    } 
    // Registrykey mit dem neuen GUID erstellen 
    strcpy (szKey, &quot;SOFTWARE\\Euklid\\Services\\&quot;) ; // 
    strcat (szKey, szGuid_class) ; 
    // neuen Schluessel erstellen 
    if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, szKey, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &amp;hKeyReg, 0) == ERROR_SUCCESS)
	{ 
        RegCloseKey (hKeyReg) ; 
        MessageBox (NULL, szGuid, &quot;Schlüssel registriert.&quot;, NULL) ; 
    } 
    else 
        MessageBox (NULL, &quot;Fehler bei Schlüssel-Erstellung&quot;, &quot;:(&quot;, MB_ICONERROR) ;
</code></pre>
<p>Kann mir jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/188315/guid-während-compile-erstellen-und-zuordnen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 07:33:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188315.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Jul 2007 10:06:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GUID während Compile erstellen und zuordnen on Mon, 30 Jul 2007 10:06:52 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Visual C++ Projekt, in dem ich einen COM server implementiere. Dies klappt einwandfrei, solange ich die GUIDs für die Objekte direkt mit einem Generator erstellen lasse und fest in die Quelldatei eintrage. Nun will ich dies allerdings während des Compile automatisch generieren lassen und den Objekten zuordnen. Dies ist irgendwie etwas schwierig, da die GUIDs im .idl file eingetragen sind und dieses keine globalen Variablen aus den c-Dateien nimmt...<br />
Hier mein .idl file:</p>
<pre><code class="language-cpp">import &quot;oaidl.idl&quot;;
import &quot;ocidl.idl&quot;;
import &quot;guid.h&quot;;

// define the ICommunication interface
[object, uuid(guid),
 oleautomation, helpstring(&quot;Handles the communication&quot;)]
interface ICommunication : IUnknown
{
	HRESULT GetDataInBSTR([out, retval] BSTR* pBstr);

};

// library statement
[uuid(guid), version(1.0),
 helpstring(&quot;Local server with typeLib&quot;)]
library LocalServerTypeInfo
{
   importlib(stdole32.tlb);
   [uuid(guid)]
   coclass LocalServer
   {
      [default] interface ICommunication;
   };
};
</code></pre>
<p>Hier mein C file zur Generierung der GUIDs:</p>
<pre><code class="language-cpp">#include &lt;Rpcdce.h&gt; // für GUID-Funktionen
#include &lt;string.h&gt; // für String-Funktionen
#include &lt;guid.h&gt;

#pragma comment(lib, &quot;Rpcrt4.lib&quot;) // Rpcrt4.lib einbinden (GUID-Funktionen) 

void fguid()

{

    unsigned char    *StringUuid ; // Zeiger für die Umwandlung 
    HKEY            hKeyReg ; // Registrykey 
    TCHAR           szKey[MAX_PATH] = &quot;SOFTWARE\\Euklid\\Services\\&quot;; // Schluessel-Path 

     // guid auf 0 setzen 
    memset (&amp;guid, '\0', sizeof (guid)) ; 
    // neuen class GUID erstellen 
    if (CoCreateGuid (&amp;guid) == S_OK){ 
        if (UuidToString (&amp;guid, &amp;StringUuid) == RPC_S_OK)
		{ // GUID in &quot;unsigned char&quot; formatieren 
            strcpy (szGuid_class, &quot;{&quot;) ; 
            strcat (szGuid_class, (char*) StringUuid) ; 
            strcat (szGuid_class, &quot;}&quot;) ; 
            RpcStringFree (&amp;StringUuid) ; 
        } 
        else
		{ 
            MessageBox (NULL, &quot;Fehler in GUID-Erstellung.&quot;, &quot;:(&quot;, MB_ICONERROR) ; 
            return 0 ; 
        } 
    } 
    else
	{ 
        MessageBox (NULL, &quot;Fehler in GUID-Erstellung&quot;, &quot;:(&quot;, MB_ICONERROR) ; 
        return 0 ; 
    } 
    // Registrykey mit dem neuen GUID erstellen 
    strcpy (szKey, &quot;SOFTWARE\\Euklid\\Services\\&quot;) ; // 
    strcat (szKey, szGuid_class) ; 
    // neuen Schluessel erstellen 
    if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, szKey, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &amp;hKeyReg, 0) == ERROR_SUCCESS)
	{ 
        RegCloseKey (hKeyReg) ; 
        MessageBox (NULL, szGuid, &quot;Schlüssel registriert.&quot;, NULL) ; 
    } 
    else 
        MessageBox (NULL, &quot;Fehler bei Schlüssel-Erstellung&quot;, &quot;:(&quot;, MB_ICONERROR) ;
</code></pre>
<p>Kann mir jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1334830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1334830</guid><dc:creator><![CDATA[RalE]]></dc:creator><pubDate>Mon, 30 Jul 2007 10:06:52 GMT</pubDate></item></channel></rss>