Questions tagged [unmanagedresources]

67 questions
2
votes
2 answers

Do I need to do MarshalAs with primitive data types from unmanaged C++ dll in C#?

I have a basic question, I have a C++ unmanaged dll that have functions with parameters in and out some unsigned char,unsigned short,unsigned long,signed char,signed short, signed long data type. Do I need to Marshal it or I can directly mapped it?…
nutcracker
  • 21
  • 1
2
votes
1 answer

Is there an inverse to []?

This post contains two inter-related questions that have cleaning up resources in common. I have read this SO post, along with several others on Microsoft's sites trying to determine what is a managed versus an unmanaged resource. Based on what I've…
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
2
votes
0 answers

Passing unmanaged resources to other classes

When using unmanaged resources, what is the best practise for passing them to other objects? I understand it should be the responsibility of the class which creates the unmanaged resource to dispose of it, but does the resource persist if I pass it…
plusheen
  • 1,128
  • 1
  • 8
  • 23
2
votes
2 answers

C# getting version of unmanaged dll

I'm calling an unmanaged dll from my managed c# code and wanted to check I'm calling the right version. The code I'm trying to load the assembly (to then get the resource file and then get the version) is: cur_version =…
probably at the beach
  • 14,489
  • 16
  • 75
  • 116
2
votes
3 answers

Calling a custom type from a DLL written in C++ from c#

I'm using a DLL written in c++ in my C# project. I have been able to call functions within the DLL using this code: [DllImport("hidfuncs", EntryPoint = "vm_hid_scan", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention =…
rross
  • 2,236
  • 11
  • 36
  • 41
2
votes
1 answer

Are there any alternative concepts for handling unmanaged resources in garbage collected languages?

Garbage collected object oriented programming languages reclaim unused memory automatically, but all other kinds of resources (i.e. files, sockets...) still require manual release since finalizers cannot be trusted to run in time (or at…
Askaga
  • 6,061
  • 5
  • 25
  • 49
2
votes
2 answers

Is System.Data.SqlClient code managed code?

Are the queries executed in a C# progamm using System.Data.SqlClient namespace cosnidered managed or umanaged code? Every time the connection is closed , (conn.Close() method is used) does the resource consider released or we have to dispose it in…
apomene
  • 14,282
  • 9
  • 46
  • 72
2
votes
1 answer

Using BitMap object without locking the resource

From an answer in a previous question, given by Hans Passant I understood that : MyImage = new Bitmap(openFileDialog1.FileName); pictureBox1.Image = (Image)MyImage; Yes, that code puts a lock on the file. The lock is produced by a memory…
Leron
  • 9,546
  • 35
  • 156
  • 257
1
vote
1 answer

Unit test if unmanaged resources are cleaned up

I'm using TDD and creating unit tests for System.IO.Stream objects that use unmanaged resources. My project consists of many such streams and I want to test if the implementations actually clean up their unmanaged resources when they are…
Tedd Hansen
  • 12,074
  • 14
  • 61
  • 97
1
vote
1 answer

Using resource string table in unmanaged dll from managed code

I have an unmanaged MFC application. I have written a CLI wrapper for the application and converted into a DLL. The unamanged code has string table resources that is used to display messages here and there. Now I can call the unmanaged code from C#…
Venkatesh Kumar
  • 642
  • 1
  • 7
  • 19
1
vote
2 answers

UnmanagedMemoryStream disposal and memory leaks

Considering the following code snippet and overlooking the lack of a using clause or an explicit disposal: public static Image GetImage(string imageName) { Image image = null; Stream unmanagedMemoryStream =…
Matt B
  • 8,315
  • 2
  • 44
  • 65
1
vote
0 answers

WPF ClickOnce Installer does not contain unmanaged dlls from nuget package

I have built and published a nuget package from a netStandard2.0 project containing unmanaged runtime specific dlls. I did this by adding following ItemGroup to my csproj file.
Quergo
  • 888
  • 1
  • 8
  • 21
1
vote
1 answer

Dispose inside a Parallel for is slower than a regular for loop. Why?

I have simplified my original issue into this test. Using this class: public class Unmanaged : IDisposable { private IntPtr unmanagedResource; public Unmanaged() { this.unmanagedResource = Marshal.AllocHGlobal(10 * 1024 *…
1
vote
1 answer

C# Force close an application and free unmanaged resources

At some point during my application I want to save a file and if it fails to quit the app, display a fail reason AND free all unmanaged resources witch is done through the distructor. While using the debug and step by step (F11) execution I have…
Ciprian Dragoe
  • 340
  • 2
  • 14
1
vote
1 answer

C# dispose unmanaged resource outside "using" and "try/finalize" block

I want a method to return an unmanaged resource and later in the program dispose of that resource. Does the following implementation do what I intend ? class DocxManager { // DocX is the unmanaged resource public Docx createDocX(string…
Ciprian Dragoe
  • 340
  • 2
  • 14