{"id":2333,"date":"2006-03-31T19:39:00","date_gmt":"2006-03-31T19:39:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2006\/03\/31\/opening-patch-files-when-compiled-for-unicode\/"},"modified":"2006-03-31T19:39:00","modified_gmt":"2006-03-31T19:39:00","slug":"opening-patch-files-when-compiled-for-unicode","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/opening-patch-files-when-compiled-for-unicode\/","title":{"rendered":"Opening Patch Files when Compiled for Unicode"},"content":{"rendered":"<p>If you want to open a <i>.msp<\/i> file with the Windows Installer APIs, you must pass <code>MSIDBOPEN_PATCHFILE<\/code> to the <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/msi\/setup\/msiopendatabase.asp\"><code>MsiOpenDatabase<\/code> function<\/a>, or <code>ERROR_OPEN_FAILED<\/code> (110) is returned. Below is the definition of both <code>MSIDBOPEN_PATCHFILE<\/code> and <code>MSIDBOPEN_READONLY<\/code> from <i>msiquery.h<\/i> in the Windows Installer SDK.<\/p>\n<p><font face=\"monospace\"><font color=\"blue\">#define<\/font> MSIDBOPEN_READONLY (LPCTSTR)0<br \/><font color=\"blue\">#define<\/font> MSIDBOPEN_PATCHFILE 32\/<font color=\"blue\">sizeof<\/font>(*MSIDBOPEN_READONLY)<\/font><\/p>\n<p><code>LPCTSTR<\/code> is defined as <code>LPCWSTR<\/code> when <code>UNICODE<\/code> is defined, which is defined as <code>wchar_t*<\/code>. Since <code>sizeof(wchar_t)<\/code> is 2, the value of <code>MSIDBOPEN_PATCHFILE<\/code> is 16 when <code>UNICODE<\/code> is defined. If you pass this to either the <code>MsiOpenDatabaseA<\/code> function or the <code>MsiOpenDatabaseW<\/code> function <code>ERROR_OPEN_FAILED<\/code> is still returned. The value must always be defined as 32.<\/p>\n<p>For the automation method <code><a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/msi\/setup\/installer_opendatabase.asp\">Installer.OpenDatabase<\/a><\/code> the second parameter must be set to <code>msiOpenDatabaseModePatchFile<\/code> to open a patch, which is always defined as 32.<\/p>\n<p>Most developers probably haven&#8217;t run into this problem yet because of support for Windows 95, 98, and Me, where Unicode is not natively supported and it&#8217;s typically undesirable to have to ship and support two bootstrap applications. Since Windows NT, 2000, XP, 2003, and future platforms support both ANSI and Unicode it makes sense to compile bootstrap applications for ANSI or MBCS. But when you choose to or need to support only Unicode, be sure to pass 32 as the <code>szPersist<\/code> parameter to <code>MsiOpenDatabase<\/code>.<\/p>\n<p><font face=\"monospace\">PMSIDATABASE hDatabase = NULL;<br \/>UINT uiError = MsiOpenDatabase(TEXT(<font color=\"maroon\">&#8220;Patch.msp&#8221;<\/font>), (LPCTSTR)32, &amp;hDatabase);<\/font><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to open a .msp file with the Windows Installer APIs, you must pass MSIDBOPEN_PATCHFILE to the MsiOpenDatabase function, or ERROR_OPEN_FAILED (110) is returned. Below is the definition of both MSIDBOPEN_PATCHFILE and MSIDBOPEN_READONLY from msiquery.h in the Windows Installer SDK. #define MSIDBOPEN_READONLY (LPCTSTR)0#define MSIDBOPEN_PATCHFILE 32\/sizeof(*MSIDBOPEN_READONLY) LPCTSTR is defined as LPCWSTR when UNICODE is [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[14,20],"class_list":["post-2333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-development","tag-installation"],"acf":[],"blog_post_summary":"<p>If you want to open a .msp file with the Windows Installer APIs, you must pass MSIDBOPEN_PATCHFILE to the MsiOpenDatabase function, or ERROR_OPEN_FAILED (110) is returned. Below is the definition of both MSIDBOPEN_PATCHFILE and MSIDBOPEN_READONLY from msiquery.h in the Windows Installer SDK. #define MSIDBOPEN_READONLY (LPCTSTR)0#define MSIDBOPEN_PATCHFILE 32\/sizeof(*MSIDBOPEN_READONLY) LPCTSTR is defined as LPCWSTR when UNICODE is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=2333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=2333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=2333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=2333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}