如何通过托管代码将非托管函数指针从dll发送到其他dll中的另一个非托管函数?
我有这个问题,我已经处理这个问题有一段时间了。一开始,我有两个带有非托管代码的 dll(比方说... dll_1、dll_2)和 C# 中的托管应用程序。我应该做的是在托管代码中获取指向 dll_1 中非托管函数的指针,将其打包到结构中,并将该结构作为参数发送给 dll_2 中的非托管函数。以前有人处理过这类问题吗?
I have this problem, which I am dealing with for some time already. At start, I have two dlls with unmanaged code (let's say... dll_1, dll_2) and managed aplication in c#. What i'm supposed to do is to get pointers to unmanaged functions in dll_1 in managed code, pack it into structure, and send this structure as an argument to unmanaged function in dll_2. Have anyone dealt with that kind of problem before maybe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您不在托管代码中执行任何操作,但 DLL 位于同一进程中,因此只需使用 IntPtr(根据平台自动为 32 或 64 位)来传递非托管指针。当然,您也可以将
IntPtr
插入结构中,并在使用外部调用时将其用作参数或返回值(例如[DllImport('YourDll')] static extern IntPtr ImportedFunction() ;
)。然而,为了给您提供更多信息,有必要了解有关 DLL 调用及其数据结构的更多信息。
Since you don't do anything in managed code but the DLLs live in the same process, just use an
IntPtr
(is automatically 32 or 64 bits depending on the platform) to pass the unmanaged pointer around. You can of course also insert theIntPtr
into your struct and use it as argument or return value when using an external call (e.g.[DllImport('YourDll')] static extern IntPtr ImportedFunction();
).However, to give you more information, it would be necessary to know more about the DLL calls and their data structures.