且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 C++ 触发 C# 中的事件并声明 LPCWSTR

更新时间:2022-11-27 12:18:23

您的代码未显示对 GpioSetupInterruptPin 的关键调用.也就是说,我认为你把它复杂化了.只需将其定义为一个字符串即可.

Your code doesn't show the critical call to GpioSetupInterruptPin. That said, I think you're over-complicating it. Just define it as a string and be done with it.

此外,我没有看到您在代码中创建命名系统事件.您发布的事件处理程序等与问题完全无关.您需要做的是 P/Invoke CreateEvent 与您传递给设置 API 的字符串名称相同,然后在该调用返回的句柄上使用 WaitForSingleObject.

Also, I'm not seeing you creating a named system event in your code. The event handlers, etc. that you posted are not at all relevant to the problem. What you need to do is P/Invoke CreateEvent with the same string name you pass to the setup API, then use WaitForSingleObject on the handle returned by that call.

开源 SDF 在托管对象 OpenNETCF.THreading.EventWaitHandle 中提供这些东西 如果您不想自己编写它们.

The open-source SDF provides these things in a the managed object OpenNETCF.THreading.EventWaitHandle if you don't want to write them yourself.