2015-11-06 131 views
0

我有一個32位程序(用C++編寫),可以連接到一些不同的設備,只要它是32位的一切正常。然而,現在我需要將它構建爲64位程序,但隨後我遇到了Windows Phone 7的一些問題。如何從64位應用程序連接到Windows Phone 7

我發現一個dll(用C#編寫),我重建爲64位引發異常在這條線:

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

(例如,如果我嘗試運行this example program工作在32位,但拋出的64位是例外,在同一行)

當我在註冊表中搜索該CLSID時,我找到了一個「C:\ Program Files(x86)\ Common Files \ Microsoft Shared \ Phone Tools \ CoreCon \ 11.0 \ Bin \ ConMan2.dll」的路徑,所以我registered that dll using regsvr32我仍然得到相同的例外。

UPDATE:

因爲我可能需要創建一個解決辦法,而不是尋找ConMan2.dll 64位版本的,我發表一點我在這裏的當前的dll的,如果有人能告訴我一個可能的解決方法,使它可以在32位和64位上工作。

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

回答

0

與CLSID = {349AB2E8-71B6-4069-AD9C-1170849DA64C} COM服務器用C實現的:\程序文件(x86)\ Common Files文件\ Microsoft共享\手機工具\ CoreCon \ 11.0 \斌\ ConMan2.dll 該DLL沒有64位版本。 而且你不能直接從64位進程使用32位DLL。

有一個解決方法。您可以創建另一個項目,即32位EXE,然後根據需要調用該32位DLL,並實現任何IPC以與主要的64位應用程序進行交互。 對於特定的IPC機制,如果您只需要調用一個相對較長的任務並等待它完成,那麼類似命令的app +命令行參數+退出代碼對我來說就足夠了。

如果您需要發出很多呼叫,我會選擇WCF通過命名管道傳輸。如果你選擇這種方式,下面是一些實現.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(); 
     } 
    } 
} 
+0

謝謝你的回答。我有一些疑問。首先,你是怎麼知道ConMan2.dll在64位版本中不存在的?第二,在前面的問題中我沒有提到它,但是我的程序是用C++編寫的,而且我用C#編寫的DLL,這種工作方式仍然適合我嗎? – Olppah

+0

1 - 在整個文件系統中搜索,該文件只在「Program Files(x86)」 – Soonts

+0

2 - 它應該工作。您可以將該DLL編譯爲「任何CPU」,將這些InteropShared,YourService,iYourService放入該DLL,在運行時檢查平臺,如果它是64位,則啓動32位主機進程並使用WCF調用該服務通過iYourService代理,如果它是32位,則創建YourService的一個實例並在同一個進程中直接與它進行交互。你會花一些時間處理不同的異常機制,但我做到了,並且它工作正常。 – Soonts

相關問題