Tag: wrapper

防止在非托管代码中使用的托管引用的垃圾回收

我的C#应用​​程序使用包装的C ++代码进行计算。 C ++标题: __declspec(dllexport) void SetVolume(BYTE* data, unsigned int width); C ++ / CLI包装器: void SetVolume(array^ data, UInt32 width) { cli::pin_ptr pdata = &data[0]; pal->SetVolume(pdata, width); } C# : public startCalc() { byte[] voxelArr = File.ReadAllBytes(“Filtered.rec”); palw.SetVolume(voxelArr, 490); //GC.KeepAlive(voxelArr); makes no sense } C ++ SetVolume函数启动异步计算。 voxelArr不再从托管端引用,并且是垃圾回收。 在非托管代码完成工作而不将voxelArr声明为全局变量之前,如何防止此引用的垃圾收集? 创建数组副本不是一个选项,因为实际上有很多数据。 startCalc()内部的主动等待也不好。

用于DOTNET的包装器用C ++ CLI编写的本机BestWay通过strutures?

然而,我正在为C ++ CLI编写一个包装器,为我们的应用程序提供一些新的部件(用C#编写),可以保存并轻松访问旧的本机库。 因此我需要将一些结构从c#传递给c ++。 这些结构在C ++ Cli(dotnet)和C ++中定义。 例: \\C+++ typedef struct { INFO16 jahr ; INFO8 monat ; INFO8 tag ; INFO8 stunde ; INFO8 minute ; } SDATUM; \\c++ cli [StructLayout(LayoutKind::Explicit)] public value struct SDATUM { public: [FieldOffset(0)] UInt16 jahr; [FieldOffset(2)] Byte monat; [FieldOffset(3)] Byte tag; [FieldOffset(4)] Byte stunde; [FieldOffset(5)] Byte minute; […]

C#Ghostscript Wrapper

有没有人在C#中遇到过GhostScript的好包装器。 我的具体用途是将postscript变成pdf

在Visual Studio 2010 Express中自动从dll生成C#包装类?

我的一位同事告诉我,Visual Studio允许一个指向.dll并自动神奇地生成一个C#包装类。 这真的有可能吗? 如果是这样,那么如何实现这一目标呢? 我浏览过网络,却未能提出任何建议! 谢谢大家! 想我也会分享这些资源, 如何:创建COM Wrappers 并且由@Darin提供 ,使用非托管DLL函数

线程安全的SortedDictionary

我创建了一个使用SortedDictionary来存储和操作数据的类。 除非在multithreading环境中实现,否则该类很有效。 现在,我想通过为内部SortedDictionary类编写包装类来使类线程安全。 我想使用Reader-Writer Locks来实现它,但是现在,我在编写包装器本身时遇到了问题。 具体来说,我不确定如何为字典实现Enumerator 。 这是我现在的完整代码。 public class ConcurrentSortedDictionary : IEnumerable<KeyValuePair> { #region Variables SortedDictionary _dict; #endregion #region Constructors public ConcurrentSortedDictionary() { _dict = new SortedDictionary(); } public ConcurrentSortedDictionary(IComparer comparer) { _dict = new SortedDictionary(comparer); } public ConcurrentSortedDictionary(IDictionary dictionary) { _dict = new SortedDictionary(dictionary); } public ConcurrentSortedDictionary(IDictionary dictionary, IComparer comparer) { _dict = […]

C#deezer native api:适应C#

我正在尝试使用C#类将C ++本机api包装到CLI C#类中。 似乎有一些问题(它确实接近工作)并希望找到问题的一些帮助。 这是包装器的代码 using System; using System.Collections; using System.Runtime.InteropServices; // make this binding dependent on WPF, but easier to use using System.Windows.Threading; // http://www.codeproject.com/Articles/339290/PInvoke-pointer-safety-Replacing-IntPtr-with-unsaf namespace Deezer { #region Enums public enum CONNECT_EVENT_TYPE { UNKNOWN, /**< Connect event has not been set yet, not a valid value. */ USER_OFFLINE_AVAILABLE, /**< User logged in, and […]

包装IEnumerable并捕获exception

我有一堆可以Process()对象的类,并返回自己的对象: public override IEnumerable Process(IEnumerable incoming) { … } 我想编写一个可以包装其中一个处理器的处理器类,并记录包装的Process()方法可能抛出的任何未捕获的exception。 我的第一个想法是这样的: public override IEnumerable Process(IEnumerable incoming) { try { foreach (var x in this.processor.Process(incoming)) { yield return x; } } catch (Exception e) { WriteToLog(e); throw; } } 但这不起作用,因为CS1626:不能在带有catch子句的try块的主体中​​产生值 。 所以我想写一些概念上等同但编译的东西。 :-)我有这个: public override IEnumerable Process(IEnumerable incoming) { IEnumerator walker; try { walker = this.processor.Process(incoming).GetEnumerator(); […]

自动创建包装器以实现接口

我有一些类没有实现某个接口,但在结构上符合该接口。 interface IFoo { void method(); } class Bar { // does not implement IFoo public void method() {…} } 现在,我可以围绕那些简单地委托给包装类的类编写一个包装器 class BarWrapper : IFoo { Bar bar = new Bar(); public void method() { bar.method(); } } 但那是繁琐的工作。 那些包装类可以自动生成吗? 就像是: IFoo foo = CreateWrapper(new Bar()); 我相信你可以用Reflection.Emit做到这一点,但我从来没有用过它,乍一看它看起来并不容易。 有没有更简单的方法,或者是否有一个库已经实现了这个?

c#中的unsigned char **等价物,必须在文件中写入返回值

我必须调用win32 dll函数 int func1( int arg1, unsigned char **arg2, int *arg3); 我需要用c#包装 public extern int fuc1(int arg1, out IntPtr arg2, out IntPtr arg3); 我从ac#application调用它 int arg1; IntPtr arg2 = IntPtr.Zero; IntPtr arg3 = IntPtr.Zero; func1(arg1,out arg2,out arg3); 函数是在c#包装器中声明的,也是在C#test app中调用的吗? 现在我需要将arg2存储在文本文件中。 怎么做。 得到了汉斯的回答,我用文件写了一个文件 System.IO.StreamWriter(@Application.StartupPath + “\\Filename.txt”); file.WriteLine(arg2); file.Close();

在C#中使用本机dll中的c ++类

我花了大约3天时间阅读这个主题…… 由于许多教程并回答了有关如何创建本机DLL的问题,我现在完全迷失了。 如果你有空闲时间,请小心解释一下这个话题,并帮助我 – 如果你没有时间,那就去那里我的问题的简单forms…… 以下是我目前对该主题的了解: 1)我需要在类名之前使用定义为__declspec(ddlexport)和__declspec(ddlimport)的宏来导出所有类方法和变量 2)我需要在某处使用extern “C” ,但我不确定到底在哪里 3)有很多方法可以做到这一点(将类作为参数传递给接受它的方法c approch / export class / use interface) 这就是我迷失的原因和方式: 1)大多数教程都是用于导出方法,我怀疑与类相比很容易(在C#中你使用[Dllimport,DLL的名称]然后你调用每个方法) 2)我是否需要在课堂上使用extern “C” ? 3)如果我使用带接口的工厂方法,我是否需要分发包含接口的.h文件? 这是我想要做的: 1)创建一个带有类的C ++ DLL,并导出要在.NET或C ++中使用的类(我想保护我的代码,因为我看到了使用存储的IL可以轻松地反转托管代码。) 2)我想有2个DLL,一个C ++本机DLL,另一个将是包装DLL,所以如果有人想在C ++中使用我的类,他可以直接使用本机DLL,如果他想在C#/ VB.net他可以使用C ++ / CLI包装器DLL … 3)没有libs,没有头文件,没有def文件,……等…..只有纯DLL(2个文件将被释放) 简单的forms 假设我想从这个C ++类中实例化C#中的对象 Class Human { private: int Pee_Meter; public: Void Do_Pee() { //stuff here }; }; […]