首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从64位应用程序连接到windows phone 7

如何从64位应用程序连接到windows phone 7
EN

Stack Overflow用户
提问于 2015-11-06 07:23:16
回答 1查看 211关注 0票数 0

我有一个32位程序(用C++编写),它可以连接到一些不同的设备,只要是32位,一切都可以正常工作。然而,现在我需要将其构建为64位程序,但后来我遇到了Windows 7的一些问题。

我发现重新构建为64位的dll (用C#编写)会在这一行抛出异常:

代码语言:javascript
复制
MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);

例外是:

代码语言:javascript
复制
An unhandled exception of type 'Microsoft.SmartDevice.Connectivity.DatastoreException' occurred in Microsoft.SmartDevice.Connectivity.dll

Additional information: Retrieving the COM class factory for component with CLSID {349AB2E8-71B6-4069-AD9C-1170849DA64C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

(例如,如果我尝试运行this example program,它在32位中工作,但在同一行中抛出64位的异常)

当我在注册表中搜索那个CLSID时,我找到了一个通往"C:\Program (x86)\Common \Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\ConMan2.dll“的路径,因此我可以找到registered that dll using regsvr32,但仍然得到相同的异常。

更新:

由于我可能需要创建一个解决方案,而不是找到一个64位版本的ConMan2.dll,所以我在这里发布了一些我当前的dll,如果有人可以向我展示一个可能的解决方案,那么它将在32位和64位中工作。

代码语言:javascript
复制
namespace WP7DLL
{
    // Interface declaration.
    [Guid("11111111-1111-1111-1111-111111111111")]
    public interface IWP7DLL
    {
        int GetStatus();
    };

    [ClassInterface(ClassInterfaceType.None)]
    [Guid("22222222-2222-2222-2222-222222222222")]
    public class WP7DLL : IWP7DLL
    {    
        public WP7DLL() { }

        public int GetStatus()
        {
             //Line that gives an exception in 64 bit
             MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
             ...
             ...           
        }
   }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-15 14:32:30

具有CLSID = {349AB2E8-71B6-4069-AD9C-1170849DA64C}的COM服务器是在C:\Program (X86)\公用文件\Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\ConMan2.dll中实现的,该DLL没有64位版本。你不能直接从64位进程中使用32位DLL.

有个解决办法。您可以创建另一个项目,32位EXE,它可以任意调用32位DLL,并实现与主64位应用程序交互的任何IPC。对于特定的IPC机制,如果您只需要调用一个相对较长的任务并等待它完成,那么类似命令的app +命令行参数+退出代码就足够了。

如果您需要发出许多调用,我会选择WCF而不是命名管道传输。如果您选择这种方式,下面是一些实现该.EXE的示例代码。

代码语言:javascript
复制
/// <summary>The class from the shared assembly that defines WCF endpoint, and named events</summary>
public static class InteropShared
{
    // Host signals it's ready and listening. Replace the zero GUID with a new one
    public static readonly EventWaitHandle eventHostReady = new EventWaitHandle( false, EventResetMode.AutoReset, @"{00000000-0000-0000-0000-000000000000}" );

    // Client asks the host to quit. Replace the zero GUID with a new one
    public static readonly EventWaitHandle eventHostShouldStop = new EventWaitHandle( false, EventResetMode.AutoReset, @"{00000000-0000-0000-0000-000000000000}" );

    const string pipeBaseAddress = @"net.pipe://localhost";

    /// <summary>Pipe name</summary>
    // Replace the zero GUID with a new one.
    public const string pipeName = @"00000000-0000-0000-0000-000000000000";

    /// <summary>Base addresses for the hosted service.</summary>
    public static Uri baseAddress { get { return new Uri( pipeBaseAddress ); } }

    /// <summary>Complete address of the named pipe endpoint.</summary>
    public static Uri endpointAddress { get { return new Uri( pipeBaseAddress + '/' + pipeName ); } }
}

static class Program
{
    /// <summary>The main entry point for the application.</summary>
    [STAThread]
    static void Main()
    {
        // The class implementing iYourService interface that calls that 32-bit DLL
        YourService singletoneInstance = new YourService();

        using( ServiceHost host = new ServiceHost( singletoneInstance, InteropShared.baseAddress ) )
        {
            // iYourService = [ServiceContract]-marked interface from the shared assembly
            host.AddServiceEndpoint( typeof( iYourService ), new NetNamedPipeBinding(), InteropShared.pipeName );
            host.Open();

            InteropShared.eventHostReady.Set();

            // Wait for quit request
            InteropShared.eventHostShouldStop.WaitOne();

            host.Close();
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33561504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档