CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    Visual C++ DLL: How to build a resource-only DLL?

    Q: How to build a resource-only DLL?

    A: On the 'Project Menu', select 'Settings'. Select the 'Link' tab of the 'Project Settings' dialog, then in the 'Project Options' box, add the '/NOENTRY' option. '/NOENTRY' prevents the linker from linking a reference to '_main' into the DLL; this option is required to create a resource-only DLL.

    Add the .RC file to an empty DLL project.

    Build the DLL.

    No MFC is involved in this process. If your application needs to access the resources from the DLL, it is easier to use the Win API functions to access these resources than MFC. You need to call 'LoadLibrary()' with the name of resource DLL, and then the Windows API 'FindResource()'/'LoadResource()'/'LoadBitmap()' etc. functions to find and load the resource.

    The reason why the API functions are easier to manage than MFC is that the API functions require that you give it the handle to the loaded DLL (the return value when you called 'LoadLibrary()'), while the MFC functions do not have this parameter. Requiring the DLL handle allows much more flexibility, since you can have multiple resource DLL's loaded, and you don't have to fool around with the 'AfxSetResourceHandle()' function (for example, compare the MFC 'LoadBitmap()' with the Windows API 'LoadBitmap()'). When you call 'AfxSetResourceHandle()', you are globally making a change to which resources your application is going to reference, which I do not like, so I don't ever use that function.

    If you want to use the MFC functions after using the API function to load your bitmap, just call the 'Attach()' method, and then the 'Detach()' method.


    FAQ contributed by: [Paul McKenzie]


    Last edited by Andreas Masur; July 25th, 2005 at 12:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured