unmanaged

Uniformly handling error codes in an unmanaged API

I'm writing a wrapper around a fairly large unmanaged API. Almost every imported method returns a common error code when it fails. For now, I'm doing this: ErrorCode result = Api.Method(); if (result != ErrorCode.SUCCESS) { throw Helper.ErrorToException(result); } This works fine. The problem is, I have so many unmanaged method ca...

Marshal.AllocHGlobal VS Marshal.AllocCoTaskMem, Marshal.SizeOf VS sizeof()

Hi. I have the following struct: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct WAVEHDR { internal IntPtr lpData; // pointer to locked data buffer internal uint dwBufferLength; // length of data buffer internal uint dwBytesRecorded; // used for input only internal IntPtr dwUser; // for c...

Best method of calling managed code(c#) from unmanaged C++

Hello, We have developed a s/w architecture consisting of set of objects developed in C#. They make extensive use of events to notify the client of changes in status, etc. The intention originally was to allow legacy code to use these managed objects through COM interop services. That was easy to write in the design specification b...

C++ internal code reuse: compile everything or share the library / dynamic library?

General question: For unmanaged C++, what's better for internal code sharing? Reuse code by sharing the actual source code? OR Reuse code by sharing the library / dynamic library (+ all the header files) Whichever it is: what's your strategy for reducing duplicate code (copy-paste syndrome), code bloat? Specific example: Here's ...

fread speeds managed unmanaged

Ok, so I'm reading a binary file into a char array I've allocated with malloc. (btw the code here isn't the actual code, I just wrote it on the spot to demonstrate, so any mistakes here are probably not mistakes in the actual program.) This method reads at about 50million bytes per second. main char *buffer = (char*)malloc(file_length_...

C# -- Create Managed Array from Pointer

Dear Sirs, I'm trying to create a Managed Array of doubles from an array of bytes. I have the problem working currently, but I wanted to optimize. Here's some code that I would like to work: private unsafe static double[] _Get_Doubles(byte[] _raw_data) { double[] ret; fixed (byte* _pd = _raw_data) { double* _pret =...

My application is unmanaged. Where do I start introducing managed code?

My whole application (which is rather big, with a 20MB executable) is written in unmanaged C++. Because I can clearly see the advantages in using managed code, I want to start introducing managed code in my application, but where do I start? Can I easily start to use C++/CLI and link it with the rest of my application? (although the C++...

Array of array initialization by using unmanaged pointers in C#

I would like to define an array of array eg int[][] on top of an existing int[] of the right size. I want then to seamlessy use either the int[][] array of array or the int[] 'big' array while refering to the same inner data. Is this possible to do this in C# using unmanaged code? In C++ I would defined pointers like this : int* bigArr...

Free unmanaged memory allocation from managed code

Hi! A .NET application calls C dll. The C code allocates memory for a char array and returns this array as result. The .NET applications gets this result as a string. The C code: extern "C" __declspec(dllexport) char* __cdecl Run() { char* result = (char*)malloc(100 * sizeof(char)); // fill the array with data return resul...

Gdiplus in C++ managed or unmanaged?

is this file with namespace Gdiplus in c++ managed or unmanaged code? ...

WinDbg -- debugging mixed x64 managed/unmanaged code

I'm using WinDbg (Native x64 -- NOT Itanium) to debug an x64 (unmanaged) application that loads both managed an unmanaged DLLs. I'm trying to set a breakpoint in one of the unmanaged DLLs. When the breakpoint is hit and I step through, the instructions displayed are totally different from what they should be. I verified with two differe...

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

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 inte...

How do I find out if a .NET assembly contains unmanaged code?

.NET assemblies that contain a mixture of managed and unmanaged code cannot be ILMerged with other assemblies. How can I verify if a given .NET assembly contains purely managed code, or a mix of managed and unmanaged code? ...

Disadvantages of calling unmanaged code from a managed C# app

What are the drawbacks to calling functions in a native library from a C# application? What can I expect for a performance hit? The functions are basic engineering computations and are nothing too complicated. We could rewrite them in C# some day. ...

How to use SafeWaitHandle.DangerousGetHandle?

I have an unmanaged code that calls an asynchronous managed method that returns a handle, and then the unmanaged code use that handle to wait, reading a little documentation I found out that SafeWaitHandle provide 2 other methods (DangerousAddRef and DangerousRelease ). Should I use these methods in order to prevent the Handle from not b...

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

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 corresp...

How to get user's OU programmatically with ldap C++

how to get user's ou programmatically with ldap C++ ...

Windows service in C# - crash/error

We have a Windows service written in C#. it is crashing after running for sometime about 5-6 hours. Our C# Windows service calls Un-Managed code which is a COM component. The only error information I get from Event Viewer is: Faulting application application.exe, version 2.2.2.0, stamp 45ed8d14, faulting module comcomponent.dl...

Referencing an unmanaged C++ project within another unmanaged C++ project in Visual Studio 2008

First of all, let me say that I am not a C++ developer. However, I am working on a neural network project that requires me to work with C++. I am working with the Flood Neural Network library. I am trying to use a neural network library in an unmanaged C++ project that I am developing. My goal is to create an instance of a class object w...

Is it possible to run Native C++ code in Windows Azure?

I have an application written in native C++ which intends intensive computation. In fact I'm interested only in result of computation, i.e. it can be done without GUI or be controlled by some .Net service/application. Can I run it in Microsoft's Cloud? How can I do it? ...