简体   繁体   English

如何在 c# 应用程序之前调用“CoInitializeSecurity”以停用 COM-Security?

[英]How do I call “CoInitializeSecurity” before an c# application to deactivate COM-Security?

I've written an WPF-Apllication in c#, that uses Bluetooth Low Energy.我用 C# 编写了一个 WPF-Application,它使用蓝牙低功耗。 The values of the BLE-device are never received by the app and googeling the problem suggests COM-Security may be the problem.应用程序永远不会收到 BLE 设备的值,谷歌搜索问题表明 COM-Security 可能是问题所在。

To solve that problem, the following website:为了解决这个问题,下面的网站:

http://microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/bluetooth-bluetoothledevicefromidasync-does-not-complete-on-10015063?forum=wdk http://microsoft.com/Forums/en-US/58da3fdb-a0e1-4161-8af3-778b6839f4e1/bluetooth-bluetoothledevicefromidasync-does-not-complete-on-10015063?forum=wdk

...suggested to call CoInitializeSecurity manually before the c# programm starts (since when the c# program starts, the function would be called implicitly and you can't call it twice). ...建议在 c# 程序启动之前手动调用CoInitializeSecurity (因为当 c# 程序启动时,该函数将被隐式调用,您不能调用它两次)。

Sadly I have no idea how to call this function, if I can't call it from my c#-sourcecode.遗憾的是我不知道如何调用这个函数,如果我不能从我的 c#-sourcecode 调用它。

Any help highly appreciated!任何帮助高度赞赏!

EDIT: http://www.pinvoke.net/default.aspx/ole32.coinitializesecurity is the best help I found so far and they state "The workaround is to write an unmanaged "shim" that will call CoInitializeSecurity, then activate and call into managed code. You can do this via an export from a mixed-mode C++ DLL, by registering a managed component for use by COM, or by using the CLR hosting API."编辑: http : //www.pinvoke.net/default.aspx/ole32.coinitializesecurity是迄今为止我找到的最好的帮助,他们指出“解决方法是编写一个非托管的“垫片”,它将调用 CoInitializeSecurity,然后激活并调用到托管代码中。您可以通过从混合模式 C++ DLL 导出、注册供 COM 使用的托管组件或使用 CLR 托管 API 来执行此操作。” I have absolutely no idea what these things mean.我完全不知道这些东西是什么意思。

I hit the same problem, and I resolved it by adding CoInitializeSecurity in App constructor.我遇到了同样的问题,我通过在 App 构造函数中添加 CoInitializeSecurity 来解决它。

App.xaml.cs应用程序.xaml.cs

public partial class App : Application
{
   App()
    {
      CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, RpcAuthnLevel.Default, RpcImpLevel.Impersonate, IntPtr.Zero, EoAuthnCap.StaticCloaking, IntPtr.Zero);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM