unmanaged

No functions in C# DLL with RGiesecke.DllExport

邮差的信 提交于 2019-12-01 05:41:27
I am trying to make a DLL in C# for use in a couple other languages. I found RGiesecke's DllExport but it doesn't seem to work. It builds just fine and makes a dll, but when I open it in Dependency Walker it doesn't show any functions, and my calling code can't find them either. I created a new "Class Library" project (VS 2013) and then installed "Unmanaged Exports (DllExport for .Net)" from NuGet. Are there any project settings I need? Here is my code. using System; using System.Collections.Generic; using System.Text; using RGiesecke.DllExport; namespace ToolServiceDLL { public class Class1 {

Managing destructors of managed (C#) and unmanaged (C++) objects

眉间皱痕 提交于 2019-12-01 05:18:23
问题 I have a managed object in a c# dll that maintains an anonymous integer handle to an unmanaged object in a c++ dll. Inside the c++ dll, the anonymous integer is used in an std::map to retrieve an unmanaged c++ object. Through this mechanism, I can maintain a loose association between a managed and unmanaged object using an anonymous integer handle. In the finalize method (destructor) of the managed object I have a call into the unmanaged dll to delete the unmanaged object. All is well as the

How to get Visual Studios build system to understand unmanaged dependencies of managed dlls?

不问归期 提交于 2019-12-01 03:56:25
When building managed code Visual Studio correctly (and recursively) copies dlls of referenced managed projects to the output folder of the project being build. However, if one the of those references is a managed DLL that depends on unmanaged dlls then these unmanaged DLLs are not copied to the output folder, even though their corresponding projects in the same solution and are listed as dependencies of the managed DLL. I realize that this problem can be resolved by having all projects use the same output folder. We already do that for most projects, but we prefer to keep unit test output

C# deallocate memory referenced by IntPtr

自作多情 提交于 2019-12-01 03:16:48
I am using some unmanaged code that is returning pointers (IntPtr) to large image objects. I use the references but after I am finished with the images, I need to free that memory referenced by the pointers. Currently, the only thing that frees the memory is to shutdown my entire app. I need to be able to free that memory from inside my application. Here is the call to that allocates the memory. hbitmap is the pointer that is returned and needs to be deallocated. [DllImport("twain_32.dll", EntryPoint = "#1")] public static extern TwainResult DsImageTransfer( [In, Out] Identity origin, [In]

Defining a delegate as a function pointer

不打扰是莪最后的温柔 提交于 2019-12-01 02:58:20
问题 I am using a delegate which calls an unmanaged function pointer. This causes the Garbage Collector to collect it before it is used, as described in the CallbackOnCollectedDelegate MDA page on MSDN: MSDN page for CallbackOnCollectedDelegate MDA. The resolution states that I have to marshal the appropriate delegate as an unmanaged function pointer. My initial reflex was to use: [MarshalAs(UnmanagedType.FunctionPtr)] public delegate void EntityCallback([MarshalAs(UnmanagedType.SysInt)] IntPtr

No functions in C# DLL with RGiesecke.DllExport

梦想与她 提交于 2019-12-01 01:21:38
问题 I am trying to make a DLL in C# for use in a couple other languages. I found RGiesecke's DllExport but it doesn't seem to work. It builds just fine and makes a dll, but when I open it in Dependency Walker it doesn't show any functions, and my calling code can't find them either. I created a new "Class Library" project (VS 2013) and then installed "Unmanaged Exports (DllExport for .Net)" from NuGet. Are there any project settings I need? Here is my code. using System; using System.Collections

How to get Visual Studios build system to understand unmanaged dependencies of managed dlls?

情到浓时终转凉″ 提交于 2019-12-01 00:18:09
问题 When building managed code Visual Studio correctly (and recursively) copies dlls of referenced managed projects to the output folder of the project being build. However, if one the of those references is a managed DLL that depends on unmanaged dlls then these unmanaged DLLs are not copied to the output folder, even though their corresponding projects in the same solution and are listed as dependencies of the managed DLL. I realize that this problem can be resolved by having all projects use

C# to C++/CLI to C DLL System.IO.FileNotFoundException

十年热恋 提交于 2019-11-30 20:06:45
I'm getting System.IO.FileNotFoundException: The specified module could not be found when running C# code that calls a C++/CLI assembly which in turn calls a pure C DLL. It happens as soon as an object is instantiated that calls the pure C DLL functions. BackingStore is pure C. CPPDemoViewModel is C++/CLI calling BackingStore it has a reference to BackingStore. I tried the simplest possible case - add a new C# unit test project that just tries to create an object defined in CPPDemoViewModel . I added a reference from the C# project to CPPDemoViewModel . A C++/CLI test project works fine with

How to serialize byte array to XML using XmlSerializer in C#?

拥有回忆 提交于 2019-11-30 17:41:05
Say we have a struct that it's data is provided by un-managed byte array using Marshal.PtrToStructure. The C# struct layout: [StructLayout(LayoutKind.Sequential, Size = 128, CharSet = CharSet.Ansi, Pack = 1)] public struct MNG_Y_Params { public byte Number; public byte Version; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] OliNumber; public byte InterfaceType; } The byte array represent a (ascii) string in the un-managed code. This struct is a member of another struct (that has some other members): public struct MyData { public int ID; public StructType structType;

Marshaling a Byte array to a C# structure

我与影子孤独终老i 提交于 2019-11-30 15:27:56
问题 I'm working on a C# project for reading FAT32 Boot Sector and BPB, The problem is that I'm using a marshaling mechanism to convert a byte array to a Custom FAT32 data structure. I get a message error saying : Could not load type 'FAT32Management.Fat32BootSector' from assembly 'FAT32Management, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 3 that is incorrectly aligned or overlapped by a non-object field. I'm not able to fix the problem