我有一个32位程序(用C++编写),它可以连接到一些不同的设备,只要是32位,一切都可以正常工作。然而,现在我需要将其构建为64位程序,但后来我遇到了Windows 7的一些问题。
我发现重新构建为64位的dll (用C#编写)会在这一行抛出异常:
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 (x86)\Common \Microsoft Shared\Phone Tools\CoreCon\11.0\Bin\ConMan2.dll“的路径,因此我可以找到registered that dll using regsvr32,但仍然得到相同的异常。
更新:
由于我可能需要创建一个解决方案,而不是找到一个64位版本的ConMan2.dll,所以我在这里发布了一些我当前的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);
...
...
}
}
}发布于 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的示例代码。
/// <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();
}
}
}https://stackoverflow.com/questions/33561504
复制相似问题