{"id":2072,"date":"2020-06-18T10:31:06","date_gmt":"2020-06-18T08:31:06","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=2072"},"modified":"2020-06-18T10:51:14","modified_gmt":"2020-06-18T08:51:14","slug":"incorrect-breaking-import-behavior-in-recent-msvc-versions","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/2072","title":{"rendered":"Incorrect breaking #import behavior in recent (e.g. 16.6.2) MSVC versions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/alax.info\/blog\/2070\">Yesterday&#8217;s bug<\/a> is not the only &#8220;news&#8221;. Some time ago I already saw weird broken behavior of rebuild of DirectShowSpy.dll with current version of Visual Studio and MSVC.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now the problem is getting more clear.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is <a href=\"https:\/\/github.com\/roman380\/gdcl.co.uk-mpeg4\/blob\/7f806bf4f80e985a1f7900181644f09916d5aa7a\/mp4mux\/Module.idl#L53\">some interface<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n    object,\n    uuid(6CE45967-F228-4F7B-8B93-83DC599618CA),\n    \/\/dual,\n    \/\/oleautomation,\n    nonextensible,\n    pointer_default(unique)\n]\ninterface IMuxFilter : IUnknown\n{\n    HRESULT IsTemporaryIndexFileEnabled();\n    HRESULT SetTemporaryIndexFileEnabled(&#91;in] BOOL bTemporaryIndexFileEnabled);\n    HRESULT GetAlignTrackStartTimeDisabled();\n    HRESULT SetAlignTrackStartTimeDisabled(&#91;in] BOOL bAlignTrackStartTimeDisabled);\n    HRESULT GetMinimalMovieDuration(&#91;out] LONGLONG* pnMinimalMovieDuration);\n    HRESULT SetMinimalMovieDuration(&#91;in] LONGLONG nMinimalMovieDuration);\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Compiled into type library it looks okay. Windows SDK 10.0.18362 COM\/OLE Object Viewer shows the correct definition obtained from the type library:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n    odl,\n    uuid(6CE45967-F228-4F7B-8B93-83DC599618CA),\n    nonextensible\n]\ninterface IMuxFilter : IUnknown {\n    HRESULT _stdcall IsTemporaryIndexFileEnabled();\n    HRESULT _stdcall SetTemporaryIndexFileEnabled(&#91;in] long bTemporaryIndexFileEnabled);\n    HRESULT _stdcall GetAlignTrackStartTimeDisabled();\n    HRESULT _stdcall SetAlignTrackStartTimeDisabled(&#91;in] long bAlignTrackStartTimeDisabled);\n    HRESULT _stdcall GetMinimalMovieDuration(&#91;out] int64* pnMinimalMovieDuration);\n    HRESULT _stdcall SetMinimalMovieDuration(&#91;in] int64 nMinimalMovieDuration);\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now what happens when MSVC <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/preprocessor\/hash-import-directive-cpp?view=vs-2019\">#import<\/a> takes it into Win32 32-bit code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct __declspec(uuid(\"6ce45967-f228-4f7b-8b93-83dc599618ca\"))\nIMuxFilter : IUnknown\n{\n    \/\/\n    \/\/ Raw methods provided by interface\n    \/\/\n\n      virtual HRESULT __stdcall IsTemporaryIndexFileEnabled ( ) = 0;\n    virtual HRESULT _VtblGapPlaceholder1( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall SetTemporaryIndexFileEnabled (\n        \/*&#91;in]*\/ long bTemporaryIndexFileEnabled ) = 0;\n    virtual HRESULT _VtblGapPlaceholder2( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall GetAlignTrackStartTimeDisabled ( ) = 0;\n    virtual HRESULT _VtblGapPlaceholder3( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall SetAlignTrackStartTimeDisabled (\n        \/*&#91;in]*\/ long bAlignTrackStartTimeDisabled ) = 0;\n    virtual HRESULT _VtblGapPlaceholder4( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall GetMinimalMovieDuration (\n        \/*&#91;out]*\/ __int64 * pnMinimalMovieDuration ) = 0;\n    virtual HRESULT _VtblGapPlaceholder5( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall SetMinimalMovieDuration (\n        \/*&#91;in]*\/ __int64 nMinimalMovieDuration ) = 0;\n    virtual HRESULT _VtblGapPlaceholder6( ) { return E_NOTIMPL; }\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">WTF <code>_VtblGapPlaceholder1<\/code>??? That was uncalled for!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It looks like some 32\/64 bullshit added by MSVC from some point (cross-compilation issue?) for no good reason reason. A sort of gentle reminder that one should get rid of <code>#import<\/code> in C++ code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please have it fixed, 32-bit code is something still being used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>#import<\/code> of Microsoft&#8217;s own quartz.dll, for example, has the same invalid gap insertion:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct __declspec(uuid(\"56a868bc-0ad4-11ce-b03a-0020af0ba770\"))\nIMediaTypeInfo : IDispatch\n{\n    \/\/\n    \/\/ Raw methods provided by interface\n    \/\/\n\n      virtual HRESULT __stdcall get_Type (\n        \/*&#91;out,retval]*\/ BSTR * strType ) = 0;\n    virtual HRESULT _VtblGapPlaceholder1( ) { return E_NOTIMPL; }\n      virtual HRESULT __stdcall get_Subtype (\n        \/*&#91;out,retval]*\/ BSTR * strType ) = 0;\n    virtual HRESULT _VtblGapPlaceholder2( ) { return E_NOTIMPL; }\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s bug is not the only &#8220;news&#8221;. Some time ago I already saw weird broken behavior of rebuild of DirectShowSpy.dll with current version of Visual Studio and MSVC. Now the problem is getting more clear. Here is some interface: Compiled into type library it looks okay. Windows SDK 10.0.18362 COM\/OLE Object Viewer shows the correct&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/2072\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[63,38,59],"class_list":["post-2072","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bug","tag-c","tag-microsoft"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=2072"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2072\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=2072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=2072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=2072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}