unmanaged

Recover From Access Violation Exception

笑着哭i 提交于 2019-12-13 06:17:57
问题 I am using EZTwain (an unmanaged dll) to process some PDF's. I am aware it can only read PDF's that it has created. Unfortunately in the real world it is encountering PDFs which have been created by other libraries. This causes it to fail and throw an AccessViolationException. This in itself is not a huge problem as my C# app continues on its way. Unfortunately when it next comes to this file and tries to reprocess it, it is still locked. Presumably EZTwain is still loaded...in what state i

Where do I put GC.KeepAlive?

a 夏天 提交于 2019-12-13 03:46:17
问题 I need to register a callback in unmanaged code, but it looks like GC keeps collecting my reference. So I added GC.KeepAlive(callback_pin); but it has no effect. I'm not sure where should I put GC.KeepAlive . This is the code where I register my own callback to the unmanaged event, it is called from a thread. (Some_Callback and Some_Method are external objects) var callback_pin = new Some_Callback(MyManagedCallback); GC.KeepAlive(callback_pin); Some_Method(callback_pin); return true; And

C# pointer to unmanaged struct with array

拟墨画扇 提交于 2019-12-13 02:53:59
问题 I am trying to implement a C style struct in C# for interoperability. Here is the struct I'm trying to convert: typedef struct { UINT8 TrafficClass0:4; UINT8 Version:4; UINT8 FlowLabel0:4; UINT8 TrafficClass1:4; UINT16 FlowLabel1; UINT16 Length; UINT8 NextHdr; UINT8 HopLimit; UINT32 SrcAddr[4]; UINT32 DstAddr[4]; } DIVERT_IPV6HDR, *PDIVERT_IPV6HDR; And here is my C# struct: [StructLayoutAttribute(LayoutKind.Sequential)] public struct DivertIPv6Header { /// TrafficClass0 : 4 /// Version : 4 //

Design: Task-Asynchronous Pattern (TAP with await / async), vs threads with signalling vs other thread structures

坚强是说给别人听的谎言 提交于 2019-12-13 00:03:27
问题 Help with ideas for redesign of the below C# program would be greatly appreciated. I am trying to pick between implementing multithreading using 1) TAP, 2) course-grained threads that contain spinners that terminate when their bools are set to false, or 3) the same threads using signalling instead of these bools. I will explain the program below, to make the case clear. The Program The program is a game automation application in C# that I am developing as a fun way to learn the language and C

System.Drawing objects unmanaged resource disposing

偶尔善良 提交于 2019-12-12 23:15:52
问题 I have the following code: using System.Drawing; ... Graphics _graphics = Graphics.FromImage(...) ... public void Draw(Stream stream, Rectangle rect, Color color) { _graphics.FillRectangle(new SolidBrush(Color), 0, 0, Width, Height); _graphics.DrawImage(new Bitmap(stream), rect); } Should I surround the drawImage with using on new Bitmap(...) ? Same question on the new SolidBrush(...) 回答1: Yes, you should wrap them in using statements. Also you should ensure that the Dispose methods is

How to use Unmanaged Exports in Delphi

淺唱寂寞╮ 提交于 2019-12-12 18:55:04
问题 I'm making a project in C# and I want to use Unmanaged Exports and later to use it in Delphi. So can anyone explain me, how does Unmanaged Exports works, then how to use/import in Delphi. I'm using Visual Studio 2010 Express, on Windows 7 64 bit 回答1: The best description I've heard for unmanaged exports is "reverse PInvoke". These are limited to scalar types, but let you consume managed assemblies from native code without the overhead of COM Interop. I haven't tried it, but you can do this in

Populate C# struct using Mupen64Plus Unmanaged C dll API command

穿精又带淫゛_ 提交于 2019-12-12 14:49:58
问题 I'm using Mupen64Plus and the included m64p_test_rom.v64 file. I'm using C# to talk to the mupen64plus.dll API which is written in C . Problem I'm trying to use its API command M64CMD_ROM_GET_HEADER to get the ROM Header from m64p_test_rom.v64 , which contains properties like Name , Manufacturer ID , Country code . It looks like the command stores the data in a struct . The problem is that when the API command is called to populate the struct , the variables remain null, it does not populate

Interface from a C DLL to .NET

此生再无相见时 提交于 2019-12-12 14:48:00
问题 I have a legacy DLL written in C that I'd like to call from a C# .NET application. The problem is that the DLL interface for the C DLL is fairly complicated. It's something like this: __declspec(dllexport) void __stdcall ProcessChunk( void *p_prochdl, const BIG_INPUT_STRC *p_inparams, BIG_OUTPUT_STRC *p_outparams ); The BIG_INPUT_STRC/BIG_OUTPUT_STRC contain all kinds of things... pointers to buffer arrays, enumerated parameters, integer parameters, etc. In short, they're complicated. First

Determining the serialized size of a .NET type and unmanaged memory efficiency

好久不见. 提交于 2019-12-12 14:17:29
问题 My question is whether it is possible to determine the serialized size (in bytes) of a reference type. Heres the situation: I am using the BinaryFormatter class to serialize basic .NET types, ie for instance: [Serializable] public class Foo { public string Foo1 { get; set; } public string Foo2 { get; set; } } I am serializing each item to a byte[], then adding that segment to the end of an existing byte[] and additionally adding a carriage return at the end of each segment to delimit the

Robert Giesecke's Unmanaged Exports

半城伤御伤魂 提交于 2019-12-12 12:40:36
问题 I'm trying to get an DllExport from vb.net to unmanaged c++ working. I'm using Robert Giesecke's Unmanaged Exports with Visual Studio 2012 and tried to follow this very helpful hints. I copy the dlls from the .Net project by an post build action in the directory where my *.cpp and *.h files reside. I checked my dll with dumpbin /EXPORTS Nugget.Discovery.dll and it tells me that there are exports: File Type: DLL Section contains the following exports for \Nugget.Discovery.dll 00000000