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

查看:322
本文介绍了如何从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 Files \ Microsoft Shared \ Phone Tools \ CoreCon \ 11.0 \ Bin \ ConMan2.dll"的路径,所以我<一个href ="https://stackoverflow.com/a/13396451/2021579">使用regsvr32注册了该dll ,但我仍然遇到相同的异常.

When I searched for that CLSID in the registry I found a path to to "C:\Program Files (x86)\Common Files\Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\ConMan2.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 Files \ Microsoft中实现共享\电话工具\ CoreCon \ 11.0 \ Bin \ ConMan2.dll 该DLL没有64位版本. 而且,您不能直接通过64位进程使用32位DLL.

The COM server with CLSID = {349AB2E8-71B6-4069-AD9C-1170849DA64C} is implemented in C:\Program Files (x86)\Common Files\Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\ConMan2.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机制,如果您只需要调用一个相对较长的任务并等待其完成,类似命令的应用程序+命令行参数+退出代码可能就足够了.

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天全站免登陆