如何避免CLR包装中的互斥? [英] How to avoid mutex in a CLR wrapper?

查看:263
本文介绍了如何避免CLR包装中的互斥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为第三方库创建.NET托管包装


http://botan.randombit.net/


但他们在许多源文件中使用互斥锁。 因此,当我尝试编译我的CLR项目时,它会失败,因为使用/ clr选项进行编译时不支持互斥锁。


我该如何解决这个问题? 我的最终目标是在C#项目中调用其库中的某些方法。


注意:部分 我需要调用的那个库中的这些方法,不要采用像int或string这样的标准C ++类型。 它们采用特定于库的类型的参数,因此我必须首先使用包装器将C#类型转换为库特定的
输入参数类型。 

解决方案

首先,我不确定你的意思/clr.nn不支持该互斥锁;使用/ clr进行编译时,CreateMutex没有理由失败。


接下来,通常只使用/clr./nbsp;编译包装器文件。将项目的其余部分保留为纯本机代码。 这也应该可以缓解您所看到的一些问题。 换句话说,不要使用/ clr编译从botan.randombit.net下载的任何文件
,只编译您创建的新文件。


I'm trying to create a .NET managed wrapper for a third party library

http://botan.randombit.net/

But they are using mutex across many of their source files.  Therefore when I try to compile my CLR project it fails because mutex is not supported when compiling with /clr option.

How can I get around this?  My end goal is to call certain methods from their library in a C# project.

Note: Some of  these methods in that library that I need to call, do not take standard C++ types like int or string.  They take parameters of types specific to the library, so I must first translate the C# type into the library specific input parameter types using the wrapper. 

解决方案

First, I am not really sure what you mean that mutex is not supported with /clr.  There is no reason that CreateMutex should fail when compiling with /clr.

Next, you would generally only compile the wrapper files with /clr.  Leave the rest of the project compiling as pure native code.  That should also mitigate some issues you are seeing as well.  In other words, don't compile any of the files you download from botan.randombit.net with /clr, only new files that you create.


这篇关于如何避免CLR包装中的互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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