如何从 64 位应用程序连接到 Windows Phone 7 [英] How to connect to windows phone 7 from a 64-bit application

查看:26
本文介绍了如何从 64 位应用程序连接到 Windows Phone 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a 32-bit program (written in C++) that can connect to some different devices and as long as it is 32-bit everything works fine. However, now I need to build it as a 64-bit program but then I came across some problems with Windows Phone 7.

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

I found out that a dll (written in C#) that I rebuilt as 64-bit throws exception at this line:

MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);

例外是:

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)).

(例如,如果我尝试运行 这个示例程序,它可以在 32 位下运行,但在64位在同一行)

(For example, if I try to run this example program it works in 32-bit but throws that exception in 64-bit at the same line)

当我在注册表中搜索该 CLSID 时,我找到了C:Program Files (x86)Common FilesMicrosoft SharedPhone ToolsCoreCon11.0BinConMan2.dll"的路径,所以我 使用 regsvr32 注册该 dll,但我仍然遇到相同的异常.

When I searched for that CLSID in the registry I found a path to to "C:Program Files (x86)Common FilesMicrosoft SharedPhone ToolsCoreCon11.0BinConMan2.dll" so I registered that dll using regsvr32 but I still get the same exception.

更新:

由于我可能需要创建一个解决方法而不是找到 64 位版本的 ConMan2.dll,如果有人可以向我展示一个可能的解决方法,我会在此处发布一些我当前的 dll,以便它可以在 32 位和 64 位中运行.

Since I might need to create a workaround instead of finding a 64bit version of ConMan2.dll, I post a bit of my current dll here if anybody can show me a possible workaround so that it will work in both 32 and 64 bit.

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);
             ...
             ...           
        }
   }
}

推荐答案

CLSID = {349AB2E8-71B6-4069-AD9C-1170849DA64C} 的 COM 服务器在 C:Program Files (x86)Common FilesMicrosoft 中实现SharedPhone ToolsCoreCon11.0BinConMan2.dll该 DLL 没有 64 位版本.而且您不能直接从 64 位进程使用 32 位 DLL.

The COM server with CLSID = {349AB2E8-71B6-4069-AD9C-1170849DA64C} is implemented in C:Program Files (x86)Common FilesMicrosoft SharedPhone ToolsCoreCon11.0BinConMan2.dll There’s no 64-bit version of that DLL. And you can’t use a 32-bit DLLs directly from a 64 bit process.

有一个解决方法.您可以创建另一个项目,即 32 位 EXE,该项目将根据需要调用该 32 位 DLL,并实现任何 IPC 以与您的主要 64 位应用程序交互.对于具体的IPC机制,如果你只需要调用一个比较长的任务并等待它完成,类似命令的app+命令行参数+退出码可能就够了.

There’s a workaround. You can create another project, 32-bit EXE, that will call that 32-bit DLL however you want, and implement any IPC to interact with your main 64-bit application. For the specific IPC mechanism, if you only need to invoke a single relatively long task and wait for it to complete, command-like app + command-line arguments + exit code may me enough for you.

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

If you need to issue many calls, I’d choose WCF over named pipe transport. If you’ll choose this way, below is some sample code implementing that .EXE.

/// <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();
        }
    }
}

这篇关于如何从 64 位应用程序连接到 Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆