unmanaged

Unmanaged Exports: Cannot compile assembly

I want to create a .NET assembly that can be accessed from unmanaged code (Delphi 5). I have found Unmanaged Exports and followed the steps there but I am unable to successfuly compile even the basic example: using RGiesecke.DllExport; namespace DelphiNET { public class Class1 { [DllExport("add")] public stati...

Convert Unmanaged to Managed During Process Hop

First, I want to thank Matt Davis for this post. I know the post was not chosen as the answer to that specific question, but the post was extremely helpful to me. I had a couple small issues to fix (mostly adjusting the filepaths in the code he provided), but I was easily able to create an unmanaged C++ client for a C# WCF service usin...

Creating a managed wrapper for 32bit and 64bit unmanaged DLL

Hi there, We are creating a C# wrapper around a unmanaged DLL. The unmanaged DLL comes in both a 32 and 64bit versions. We keep the managed wrapper in its own project so that we can build it as a separate component and reuse it across solutions. However this leads to some problems. Since the unmanaged DLL has the same name for both t...

How to send unmanaged function pointers from dll to another unmanaged function in other dll through managed code?

Hi! I have this problem, which I am dealing with for some time already. At start, I have two dlls with unmanaged code (let's say... dll_1, dll_2) and managed aplication in c#. What i'm supposed to do is to get pointers to unmanaged functions in dll_1 in managed code, pack it into structure, and send this structure as an argument to unman...

Where should I place unmanaged .dlls in a .NET project using VS2008?

So far I've been placing the dll into the /bin folder because it seems to be the only place it will get loaded when a DllImport'd function is called, but it just doesn't feel right since it's the output folder and it'll probably be wiped after a 'project clean' or 'rebuild all' operation. How should I do this? Thanks in advance. Note: ...

Howto implement callback interface from unmanaged DLL to .net app?

Hi, in my next project I want to implement a GUI for already existing code in C++. My plan is to wrap the C++ part in a DLL and to implement the GUI in C#. My problem is that I don't know how to implement a callback from the unmanaged DLL into the manged C# code. I've already done some development in C# but the interfacing between manage...

Memory allocators for a native C++ library to be used by C#

I'm writing some native C++ code which needs to be called from C# (and I can't replace the C++ native code with C# code). I found memory corruptions while allocating/deallocating some memory in the native C++ code using malloc/free. Then I used LocalAlloc/LocalFree and HeapAlloc/HeapFree and had the same problems. The allocations/deall...

Marshal.PtrToStringUni() vs new String() ?

Suppose i have a pointer of type char* to unicode string, and i know the length: char* _unmanagedStr; int _unmanagedStrLength; and i have 2 ways to convert it to .NET string: Marshal.PtrToStringUni((IntPtr)_unmanagedStr, _unmanagedStrLength); and new string(_unmanagedStr, 0, _unmanagedStrLength); In my tests, both calls gives me...

Using C++\C# .Net assemblies\DLL's in win32 C++ (unmanaged) application

There is any way to use C++\C# .Net assemblies\DLL's in win32 C++ (unmanaged) applications? ...

How to wrap a C library so that it can be called from a web service

We have a library with very complex logic implemented in C. It has a command line interface with not too complex string-based arguments. In order to access this, we would like to wrap the library so that it can be accessed with simple XML RPC or even straightforward HTTP POST calls. Having some experience with Java, my first idea would ...

Marshalling what is it and why do we need it?

What is marshalling and why do we need it. I find it hard to believe that i cannot send an int over the wire from c# to c and have to marshall it. Why cant c# just send the 32bits over with a starting and terminating signal, telling C code that it has received an int. If there are any good tutorials or sites about why we need marshallin...

C# class representing a USB device

I'm writing a wrapper class in C# for a USB device (using P/Invoke to communicate with it). The device needs to be sent an open message before use, and a close method when it's done with. In my constructor I want to try to open the device and return null if that call fails for whatever reason. I'll also write a Dispose() which calls the ...

Problem with x64 application and ActiveX control

Hi, I have a small unmanaged c++ application, I'm trying to use CoCreateInstance(...) to create an instance of the "Adobe SVG PLayer" which is installed as an ActiveX control. When I compile and run my application under 32-bit configuration, it works fine, but when I compile under 64-bit configuration, my application fails to create the...

C# deallocate memory referenced by IntPtr

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

Passing objects between C# and C

Hi, My application consist of C# code with unmanaged C dll calls. In my C# code I have an object/class where its properties are both system types such as string and int and other objects I have defined. I would like to pass this complex (Graph.cs) object to my C (dll) code, what implementation would you suggest here? I have tried movin...

Initialize unmanage struct from managed code (C#)

I have a structure in C++ that I want to reflect in C# code (goover all field and initiate with specific order) that I want to dump the structure memeory as binary data into a file. I have a problem in array decleration in the sturct if I declare int dummy_4[10] the compiler raise error that can't mix managed & unmanaged types. if I dela...

How to unload the default .NET AppDomain from an unmanaged application

Is there a way to unload the default .NET AppDomain from an unmanaged application? I'm using a third party tool called .NET Extender for using .NET assemblies from within Visual FoxPro which allows me to host .NET controls and also make use of .NET classes and methods from within a FoxPro environment. The problem I'm having is that whe...

Catching "Run-Time Check Failure #0 - The value of ESP was not properly "

So, I am calling a function from an unmanaged .dll file from my C# code. Depending on the arguments passed to that function, it can cause "Run-Time Check Failure #0 - The value of ESP was not properly " error.This is completely normal behavior for the function ( yes , I know this sounds VERY strange, but bear with me ). However, if this ...

unmanaged C program that statically links to a managed DLL: load failure

Yes, this is probably too long. Apologies in advance: This is another iteration of my previous question which was specific to remote desktop. We have an existing product consisting of many programs, which are built in (unmanaged) C. In the recent past we have started adding .NET (managed) applications to our product. A major part o...

passing parameters to unmanaged C api from vb.net

I need to call a function in an unmanaged .dll written in C lang from vb.net. The function declaration looks like this LONG _stdcall ReadInfo(char *reply); Now the behavior of this function is that it copies some data in argument "reply" and returns a numeric value which signals its pass/fail status. How do i pass it a string object so...