<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problems With Resource DLL in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6051687#M10352</link>
    <description>&lt;P&gt;I've put my resources in a resource only DLL, which I build as an extension DLL. In my app initialisation, I load the resource DLL with &lt;FONT face="courier new,courier"&gt;LoadLibraryEx&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE&lt;/FONT&gt;. I then insert it into the resource chain by intialising a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CDynLinkLibrary&lt;/FONT&gt; member.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It was my understanding that resource DLLs added this way are added to the begining of the resource search path - meaning resources should be found in my DLL first. However, it seems my resource &lt;FONT face="courier new,courier"&gt;LoadStrings&lt;/FONT&gt; (for example) are coming from AutoCAD, and the only way to fix this (so far) is to specifically &lt;FONT face="courier new,courier"&gt;FindResource&lt;/FONT&gt; using my resource handle. This is easy enough for strings, more complicatied for dialog templates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to avoid having to constantly change my resource handle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to ensure the resource search order is as I want it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I can't get my resource DLL to the front of the queue, is there a published list of resource IDs to use so as to avoid conflict with AutoCAD IDs?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2016 01:17:59 GMT</pubDate>
    <dc:creator>Kyudos</dc:creator>
    <dc:date>2016-02-23T01:17:59Z</dc:date>
    <item>
      <title>Problems With Resource DLL</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6051687#M10352</link>
      <description>&lt;P&gt;I've put my resources in a resource only DLL, which I build as an extension DLL. In my app initialisation, I load the resource DLL with &lt;FONT face="courier new,courier"&gt;LoadLibraryEx&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE&lt;/FONT&gt;. I then insert it into the resource chain by intialising a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CDynLinkLibrary&lt;/FONT&gt; member.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It was my understanding that resource DLLs added this way are added to the begining of the resource search path - meaning resources should be found in my DLL first. However, it seems my resource &lt;FONT face="courier new,courier"&gt;LoadStrings&lt;/FONT&gt; (for example) are coming from AutoCAD, and the only way to fix this (so far) is to specifically &lt;FONT face="courier new,courier"&gt;FindResource&lt;/FONT&gt; using my resource handle. This is easy enough for strings, more complicatied for dialog templates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to avoid having to constantly change my resource handle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to ensure the resource search order is as I want it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I can't get my resource DLL to the front of the queue, is there a published list of resource IDs to use so as to avoid conflict with AutoCAD IDs?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 01:17:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6051687#M10352</guid>
      <dc:creator>Kyudos</dc:creator>
      <dc:date>2016-02-23T01:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problems With Resource DLL</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6052035#M10353</link>
      <description>&lt;P&gt;As far as I know you definetley need to switch the resource handle temporary yourself. Setting the resource handle to your own resource permanantly could cause AutoCAD to fail. Have a look at the class &lt;FONT face="courier new,courier"&gt;CAcModuleResourceOverride.&lt;/FONT&gt; It is very easy to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;From &amp;lt;ARX&amp;gt;\inc\AcExtensionModule.h:

/////////////////////////////////////////////////////////////////////////////
// CAcModuleResourceOverride - Switch between default and module's resources
//
//   Use an instance of this class to switch between resource providers. When
// the object is constructed a new resource provider will get switched in.
// Upon destruction the original resource provider will be restored. For
// example:
//
//      void MyFunc ()
//      {
//          CAcModuleResourceOverride myResources;
//              .
//              .
//      }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 09:41:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6052035#M10353</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2016-02-23T09:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problems With Resource DLL</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6053189#M10354</link>
      <description>&lt;P&gt;But doesn't&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CAcModuleResourceOverride&lt;/FONT&gt; switch to the resources in the ARX file? My resources are in a separate file. Anyway, it would be easy enough to make my own version of it, but I'd still have to go through hundreds of source files and add it in there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isn't the whole idea of the extension DLL system so you DON'T have to keep flipping your resource handles? It would&amp;nbsp;be easier - and one less thing to remember to do - if I could make my DLL the first in the resource chain. Failing that I could change my IDs to something more 'unusual' - but only if I know what ID ranges AutoCAD uses.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 20:17:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6053189#M10354</guid>
      <dc:creator>Kyudos</dc:creator>
      <dc:date>2016-02-23T20:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problems With Resource DLL</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6053956#M10355</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; But doesn't&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CAcModuleResourceOverride&lt;/FONT&gt; switch to the resources in the ARX file? My resources are in a separate file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to make sure that the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CAcExtensionModule&lt;/FONT&gt; object stores your resource handle in&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CAcExtensionModule::m_hDefaultResource&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;Look into the header file &amp;lt;ARX&amp;gt;\inc\AcExtensionModule.h. It's pretty obvious. This is how you can do it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// Define a CAcExtensionModule at global scope:&lt;BR /&gt;AC_IMPLEMENT_EXTENSION_MODULE(theArxDLL); &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // expands to:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CAcExtensionModule theArxDLL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CAcExtensionModule&amp;amp; CAcModuleResourceOverride::m_extensionModule = theArxDLL;&lt;BR /&gt;&lt;BR /&gt;extern "C" int APIENTRY&lt;BR /&gt;DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) &lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if (dwReason == DLL_PROCESS_ATTACH)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HINSTANCE hResOld = AfxGetResourceHandle();&amp;nbsp;&amp;nbsp; // store the original Resource Handle&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HINSTANCE hMyResource = LoadLibrary(&amp;lt;myResDllPath&amp;gt;);&amp;nbsp; // Load your Resource DLL or get its handle&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AfxSetResourceHandle(hMyResource);&amp;nbsp;&amp;nbsp; // temporary set your Resource Handle...&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theArxDLL.AttachInstance(hInstance); // ..to make sure that theArxDLL grabs your Resource Handle when calling AfxGetResourceHandle()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AfxSetResourceHandle(hResOld);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // restore to the original handle&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else if (dwReason == DLL_PROCESS_DETACH)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theArxDLL.DetachInstance();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return 1;&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to admit that I'm not sure wether LoadLibrary() will work within DllMain(). If not you could move the code to initModule() (acrxEntryPoint(AcRx::kInitAppMsg,..))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Isn't the whole idea of the extension DLL system so you DON'T have to keep flipping your resource handles?&lt;/P&gt;&lt;P&gt;&amp;gt;It would&amp;nbsp;be easier - and one less thing to remember to do - if I could make my DLL the first in the resource chain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sure it would be easier. But AutoCAD itself and maybe other extension modules use their own resource DLLs as well. So you can't ever rely on the current resource handle being yours. This is why you need the flipping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; ...have to go through hundreds of source files and add it in there.&lt;/P&gt;&lt;P&gt;You should add this to functions that need to access the resources. I.e. if you have resource Strings use a function like &lt;FONT face="courier new,courier"&gt;CString resStr(int id) {...}&lt;/FONT&gt; that does the flipping before retrieving the string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 08:54:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6053956#M10355</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2016-02-24T08:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problems With Resource DLL</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6055118#M10356</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;gt; You should add this to functions that need to access the resources. I.e. if you have resource Strings use a function like&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;gt; CString resStr(int id)&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;{...}&lt;/FONT&gt;&lt;SPAN&gt; that does the flipping before retrieving the string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Yeah, I already did this on my string an icon retrieval functions while investigating the problem. It's not quite so easy with dialog templates in MFC - anyway it seems obvious I'll just have to bite the bullet and do the flipping.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 20:04:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/problems-with-resource-dll/m-p/6055118#M10356</guid>
      <dc:creator>Kyudos</dc:creator>
      <dc:date>2016-02-24T20:04:07Z</dc:date>
    </item>
  </channel>
</rss>

