{"id":42973,"date":"2003-08-07T00:35:00","date_gmt":"2003-08-07T00:35:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/08\/07\/limitations-on-dll-resources-in-windows-95\/"},"modified":"2003-08-07T00:35:00","modified_gmt":"2003-08-07T00:35:00","slug":"limitations-on-dll-resources-in-windows-95","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030807-00\/?p=42973","title":{"rendered":"Limitations on DLL resources in Windows 95"},"content":{"rendered":"\n<p>         Ancient history lesson.      <\/p>\n<p>         When Win9x loads a 32-bit DLL, it creates a shadow 16-bit DLL so 16-bit code (like         USER) can access resources in it.      <\/p>\n<p>         The shadow DLL is effectively a resource-only 16-bit DLL, created by taking the 32-bit         resources and converting them to 16-bit format. If the resources cannot be converted         to 16-bit format, the DLL will not load.      <\/p>\n<\/p>\n<p>         The 16-bit resource file format specifies resource sizes by combining a DLL-wide shift         value with a 16-bit per-resource scaled size. So, for example, if the shift value         were 2, and the per-resource scaled size were 8, then the actual resource size would         be 8 &lt;&lt; 2 = 32.      <\/p>\n<p>         Windows 95 has a bug in the way it calculates the scaled size.      <\/p>\n<p>         If the Windows 95 kernel decided that it needed to use a nonzero shift value because         the 32-bit DLL contains a resource larger than 64K, it scaled the 32-bit values down         to 16-bit values and rounded <em>down<\/em> rather than up. So, for example, if a resources         were 65537 bytes in size and the shift factor were 1, then the scaled-down value would         be 65537 &gt;&gt; 1 = 32768. After scaling back up, the result would be 32768 &gt;&gt;         1 = 65536. Notice that the value is too small; the last byte of the resource has been         truncated.      <\/p>\n<p>         Consequently, if you have a 32-bit DLL with resources 64K or larger, you must pad         those resources to prevent this truncation from happening. In the above example, you         would have to pad the resource to 65538 bytes, so that the scaled-down value would         be 32769, which scales back up to 65538.      <\/p>\n<p>         I believe this bug was fixed in Windows 98 but I&#8217;m not sure. <a href=\"http:\/\/support.microsoft.com\/default.aspx?scid=http:\/\/support.microsoft.com:80\/support\/kb\/articles\/Q182\/8\/19.ASP&amp;NoWebContent=1\">There         is a little program in the SDK called fixres95 that generates the necessary padding<\/a>.      <\/p>\n<p>         Other limitations of the 16-bit resource file format you may run into:      <\/p>\n<ul>\n<li>             <a href=\"http:\/\/support.microsoft.com\/default.aspx?scid=kb;en-us;137248\">Ordinal resource             identifiers may not exceed 32767<\/a>.          <\/li>\n<li>             The total lengths of named resources may not exceed 65535 (where each name counts             one byte for each character in the name, plus one). Named resources have been a bad             idea since Windows 1.0. They are a convenience that you can easily live without most             of the time, and they are significantly more costly, as you can see.          <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Ancient history lesson. When Win9x loads a 32-bit DLL, it creates a shadow 16-bit DLL so 16-bit code (like USER) can access resources in it. The shadow DLL is effectively a resource-only 16-bit DLL, created by taking the 32-bit resources and converting them to 16-bit format. If the resources cannot be converted to 16-bit format, [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-42973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Ancient history lesson. When Win9x loads a 32-bit DLL, it creates a shadow 16-bit DLL so 16-bit code (like USER) can access resources in it. The shadow DLL is effectively a resource-only 16-bit DLL, created by taking the 32-bit resources and converting them to 16-bit format. If the resources cannot be converted to 16-bit format, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=42973"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=42973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=42973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=42973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}