Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You cannot embedd MFC resources inside a class or similar C++ container. They can only be embedded in DLL or EXE files - in a separate section of the produced binary. Since you want your class to be reusable, you must put it in a DLL. Hence, you must tag your class with the <a href="http://msdn.microsoft.com/en-us/library/9xyb5w93%28v=vs.80%29.aspx" rel="nofollow">AFX_EXT_CLASS</a> keyword.</p> <p>There are two solutions.</p> <p><strong>Solution #1:</strong></p> <ul> <li>Create an MFC DLL project (<code>MFC Extension DLL</code>). Call it <code>MyLibrary</code> or whatever.</li> <li>Put all your standalone classes in this DLL.</li> <li>Embed all necessary resources.</li> <li>Let your classes load resources from the <code>HINSTANCE</code> of your DLL as described below.</li> </ul> <p>There are several ways to retrieve the <code>HINSTANCE</code> of your DLL. If you ask me, the best solution is to grab it in <code>DllMain</code>. This is done automatically if you choose the <code>MFC Extension DLL</code> configuration:</p> <pre><code>static AFX_EXTENSION_MODULE MyLibDLL = { NULL, NULL }; // Make this variable global! // Then access the hInstance as follows: LoadResource(MyLibDLL.hModule, ...) </code></pre> <p><strong>Solution #2:</strong></p> <p>Store your resource as a byte buffer. Or better, convert it to <a href="http://www.google.se/url?sa=t&amp;rct=j&amp;q=base64&amp;source=web&amp;cd=2&amp;sqi=2&amp;ved=0CFcQFjAB&amp;url=http://en.wikipedia.org/wiki/Base64&amp;ei=uRIqUOCIOarg4QTS84CYDg&amp;usg=AFQjCNFxJAMXAr4Jc-0wQvhcp_q4nZlf5w" rel="nofollow">Base64</a> and store it as an ASCII string. But remember not to blow the stack! Keep your resources small or increase the stack size in your project settings. Example:</p> <pre><code>const char *encodedResource = "SGVsbG8gd29ybGQh"; char *data = decode(encodedResource); foo(data); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload