unmanagedresources

Need to implement a finalizer on a class that uses TcpClient?

I have a class (say MyClass) that uses (has as a private field) a TcpClient object. MyClass implements IDisposable calling TcpClient.Close in the Dispose method. My question is should MyClass also implement a finalizer to call Dispose(bool Disposing) to free the TcpClient’s unmanaged resources in case MyClass.Dispose is not called by t...

unmanaged dll code

I am having a C# (.NET 3.5, VS2005 Professional) application that uses unmanaged 32bit library written in C/C++. API that I use is like this: void * Initialize(int x); voic GetData(void *); And this works when I run it on Windows XP 32bit, but on Windows XP64bit it throws exception: Unhandled Exception: System.Reflection.TargetInvoca...

List of cases where USING statement should be employed

"File and Font are examples of managed types that access unmanaged resources (in this case file handles and device contexts). There are many other kinds of unmanaged resources and class library types that encapsulate them. All such types must implement the IDisposable interface. As a rule, when you use an IDisposable object, you should ...

Are the database-related objects such as connection object, command object, datareader, dataadapter,... unmanaged resources?

hi Are the database-related objects such as connection object, command object, datareader, dataadapter,... unmanaged resources? ...

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 = CallingConvention.Cdecl)] public static extern IntPtr VmHidScan(); Now I need to call a functi...

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 = Assembly.LoadFile("X:\Workspace\yreceipts_pos\yRprintProcessor\Debug\yRprintProcessor.dll"); It's failing because...

Unmanaged C code in C# Marshalling by ref string array!

Hi All, I am having a really hard time getting this marshalling down. I have umanaged code that looks like this: WORD HLP_GetDeviceNames (LPSTR *DevNames, WORD Max_Len, WORD Max_Num) Just FYI I did not write this unmanaged code but must use it. Returns: WORD indicating an error. DevNames: Pointer to an array of char arrays. Basic...

Should Marshal.FreeHGlobal be placed in a finally block to ensure resources are disposed?

I have the following block of code: IntPtr unmanagedPointer = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, unmanagedPointer, buffer.Length); SomeCommandThatCanThrowAnException(); Marshal.FreeHGlobal(unmanagedPointer); Should the block be wrapped in a try, and the FreeHGlobal command be placed in a finally block. (In ca...