从托管代码调用DLL(非托管)中的方法 [英] calling a method in a DLL (unmanaged) from managed code

查看:113
本文介绍了从托管代码调用DLL(非托管)中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我已经用C ++编写了Dll. DLL具有公开的功能,其中我使用new运算符分配运行时内存. dll是从非托管多线程应用程序调用的.

我遇到一个问题,当客户端应用程序(C#)调用我的dll时,运行时内存分配会崩溃.

您能帮我使用哪个堆函数吗?


如果解决方法

如果调用者负责释放由.DLL函数分配的内存,则.DLL也应公开一个函数供调用者使用以释放该对象.记忆.您不应该依赖调用方来了解.DLL用于分配内存块的哪种分配方法.


阅读本文

http://blogs.msdn.com/b/jonathanswift/archive/2006/10/02/780637.aspx [ ^ ]


但唯一需要注意的是您无法在托管代码中调用MFC Extension dll函数


Hi all

I have written a Dll in c++. The Dll has a exposed function in which i allocate run-time memory using new operator. The dll is called from unmanaged multi-thread apps.

I am facing a issue that run-time memory allocation is getting crashed when the client app (C#) call my dll.

Can you help me to which heap-function should i use ?


thanks

解决方案

If the caller is responsible for freeing the memory allocated by the .DLL function, the .DLL should also expose a function for the caller to use to free that memory. You should NOT be relying on the caller to know which method of allocation the .DLL used to allocate a block of memory.


Read this article

http://blogs.msdn.com/b/jonathanswift/archive/2006/10/02/780637.aspx[^]


but only concern is you can not call MFC Extension dll function in your managed code


这篇关于从托管代码调用DLL(非托管)中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆