64位侧装应用程序使用Brokered Windows运行时组件
我有一个32位(x86)侧装Windows Store app
,与代理的Windows运行时组件一起工作,它工作顺利,可以启动桌面EXE,使用加载桌面DLL反射等64位侧装应用程序使用Brokered Windows运行时组件
我想使这个侧装应用程序64位。在将应用程序重新构建为x64后,它不能再次使用代理的Windows运行时组件。该错误是
Additional information:
Unable to cast COM object of type 'StoreAppBrokeredWindowsRuntimeComponent.DirectInvoker' to interface type 'StoreAppBrokeredWindowsRuntimeComponent.IDirectInvokerClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{50EA3FD3-2383-5445-4002-8CBCBED5DB0F}' failed due to the following error: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
从DOC Brokered Windows Runtime Components for a side-loaded Windows Store app,
Side-loaded applications can be 64-bit (provided there is both a 64-bit and 32-bit proxies registered), but this will be atypical.
问:
如何建立一个64位的代理?
VS template只能建立32位(Win32)代理。如果将WindowsRuntimeProxyStub
更改为x64,则甚至无法编译 - 有一堆LINK错误。
所以32位侧载应用程序,32位的Windows斡旋运行时组件,和32位代理是只有工作方法为止。
在Microsoft支持人员的帮助下,我成功构建了64位代理运行时组件,并使用它从64位侧装应用程序中运行。
为了便于理解,只需使用以下MS示例项目即可。你根本不需要修改任何代码文件。但是,您需要首先修复模板中的两个错误,请参阅本答案末尾的重要注意事项。
Brokered Windows Runtime Components for side-loaded Windows Store apps - Server
Brokered Windows Runtime Components for side-loaded Windows Store apps - Client
步骤以生成64位的牵线组分和代理
解压缩代码包(经纪人的Windows运行时组件侧装载Windows应用商店的应用程序 - Server.zip)并使用Visual studio 2013打开解决方案(以管理员身份运行);
将
SampleProxy
项目的平台从Win32更改为x64;打开
SampleProxy Property
- >Configuration Properties
- >Preprocessor
- >Preprocessor Definitions
,并改变两个定义
WIN32->X64; REGISTER_PROXY_DLLWIN32->REGISTER_PROXY_DLL
更改
EnterpriseIPCServer
项目的至x64平台。编辑生成后的
EnterpriseIPCServer
事件命令行,取代的x86
或Win32
与x64
每次出现时,该命令应该是这样的:首先构建
EnterpriseIPCServer
项目。然后建立
SampleProxy
项目。
call "$(DevEnvDir)..\..\vc\vcvarsall.bat" x64
md "$(TargetDir)"\impl
md "$(TargetDir)"\reference
erase "$(TargetDir)\impl\*.winmd"
erase "$(TargetDir)\impl\*.pdb"
rem erase "$(TargetDir)\reference\*.winmd"
xcopy /y "$(TargetPath)" "$(TargetDir)impl"
xcopy /y "$(TargetDir)*.pdb" "$(TargetDir)impl"
winmdidl /nosystemdeclares /metadata_dir:C:\Windows\System32\Winmetadata "$(TargetPath)"
midl /metadata_dir "%WindowsSdkDir%References\CommonConfiguration\Neutral" /iid "$(SolutionDir)SampleProxy\$(TargetName)_i.c" /env x64 /x64 /h "$(SolutionDir)SampleProxy\$(TargetName).h" /winmd "$(TargetName).winmd" /W1 /char signed /nologo /winrt /dlldata "$(SolutionDir)SampleProxy\dlldata.c" /proxy "$(SolutionDir)SampleProxy\$(TargetName)_p.c" "$(TargetName).idl"
mdmerge -n 1 -i "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)" -o "$(TargetDir)reference" -metadata_dir "%WindowsSdkDir%References\CommonConfiguration\Neutral" -partial
rem erase "$(TargetPath)"
检查输出文件(Fabrikam.winmd & SampleProxy.dll)。
步骤来使用64位牵线组分和代理
足够棘手,64位促成运行时组件从未使用的。我们所需要的只是32位中介运行时组件,但我们需要注册这两个 32位和64位代理。
将3个文件(32位代理运行时组件+ 2代理)放在同一文件夹下,例如C:\ test。然后执行以下命令。
regsvr32.exe C:\test\SampleProxy_64.dll (I have renamed the 64-bit proxy)
regsvr32.exe C:\test\SampleProxy.dll (this is the 32 bit proxy)
icacls C:\test /T /grant "ALL APPLICATION PACKAGES":RX
然后在64位侧载应用程序中,引用32位代理运行时组件。但要小心挑选“reference”文件夹中的文件夹,不要引用“impl”文件夹中的文件夹。
仅供参考,我已将代码上传至this GitHub repository。
重要事项
有在此示例项目的一些错误,这使它成为一个恶梦建立它为x86/win32的配置。
在EnterpriseIPCServer的x86的结构,在后生成事件以下命令包含不可辨认的开关/86,它应该是/win32的。
midl /metadata_dir "%25WindowsSdkDir%25References\CommonConfiguration\Neutral" /iid "$(SolutionDir)SampleProxy\$(TargetName)_i.c" /env win32 /x86 /h "$(SolutionDir)SampleProxy\$(TargetName).h" /winmd "$(TargetName).winmd" /W1 /char signed /nologo /winrt /dlldata "$(SolutionDir)SampleProxy\dlldata.c" /proxy "$(SolutionDir)SampleProxy\$(TargetName)_p.c" "$(TargetName).idl"
在SampleProxy项目,预处理器定义REGISTER_PROXY_DLLWIN32之一的Win32配置应该是REGISTER_PROXY_DLL。