VC++ resources in a static library

前端 未结 7 1966
天涯浪人
天涯浪人 2020-11-29 21:30

Is it possible to build resources into a static library and reuse them by simply linking with the library?

I\'m primarily thinking about the case where you call a fu

7条回答
  •  感动是毒
    2020-11-29 22:09

    When the following method is used, any resource (in this example, an icon) can be used as an integral part of a static library and such library can be used by any type of application, including a console one (which doesn't have any resource segment whatsoever).

    1. Icon is converted to a static array of BYTE. bin2c can be used for that.
    2. Data is converted into a HICON handle. Here is how I have done that:

      HICON GetIcon()
      { 
         DWORD dwTmp;
         int offset;
         HANDLE hFile;
         HICON hIcon = NULL;
         offset = LookupIconIdFromDirectoryEx(s_byIconData, TRUE, 0, 0, LR_DEFAULTCOLOR);
         if (offset != 0)
         {
            hIcon = CreateIconFromResourceEx(s_byIconData + offset, 0, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
         }
         return hIcon;  
      }
      
    3. GetIcon is used instead of LoadIcon. Instead of calling:

    m_hIcon = ::LoadIcon(hInstanceIcon, MAKEINTRESOURCE(pXMB->nIcon));

    Then call

    m_hIcon = GetIcon()
    

提交回复
热议问题