unmanaged

allocating “unmanaged” memory in c#

情到浓时终转凉″ 提交于 2019-11-26 20:25:37
问题 I'm writting a program in c# that uses a C++ library, and for some reason I need to allocate an unmanaged buffer to pass it to the lib. Is there a way to do this in c# ? Basically I would just need to do a malloc in C#... Thanks 回答1: Try something like this: using System; using System.Runtime.InteropServices; class Example { static void Main() { IntPtr pointer = Marshal.AllocHGlobal(1024); } } This uses the Marshal.AllocHGlobal method: Allocates memory from the unmanaged memory of the process

Unmanaged DLLs fail to load on ASP.NET server

空扰寡人 提交于 2019-11-26 18:30:21
This question relates to an ASP.NET website, originally developed in VS 2005 and now in VS 2008. This website uses two unmanaged external DLLs which are not .NET and I do not have the source code to compile them and have to use them as is. This website runs fine from within Visual Studio, locating and accessing these external DLLs correctly. However, when the website is published on a webserver (runnning IIS6 and ASP.NET 2.0) rather than the development PC it cannot locate and access these external DLLs, and I get the following error: Unable to load DLL 'XYZ.dll': The specified module could

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

本秂侑毒 提交于 2019-11-26 17:34:59
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 managed and unmanaged code is new to me. Can anybody give me some hints or reading tips or a simple example to start from? Unfortunatly I could not find anything helpful. You don't need to use Marshal.GetFunctionPointerForDelegate(), the P/Invoke marshaller does it

A call to PInvoke function '[…]' has unbalanced the stack

↘锁芯ラ 提交于 2019-11-26 16:32:01
I'm getting this weird error on some stuff I've been using for quite a while. It may be a new thing in Visual Studio 2010 but I'm not sure. I'm trying to call a unamanged function written in C++ from C#. From what I've read on the internet and the error message itself it's got something to do with the fact that the signature in my C# file is not the same as the one from C++ but I really can't see it. First of all this is my unamanged function below: TEngine GCreateEngine(int width,int height,int depth,int deviceType); And here is my function in C#: [DllImport("Engine.dll", EntryPoint =

How do I add a reference to an unmanaged C++ project called by a C# project?

拜拜、爱过 提交于 2019-11-26 15:45:38
问题 One solution (the.sln) One C++ project (mycppproject.vcxproj in 2010or mycppproject.vcproj in 2008) which compiles a native DLL exporting some function(s). In debug this builds c:\output\Debug\mycppproject_d.dll and in release this builds c:\output\Release\mycppproject.dll. One C# console application (mycsharpconsole.csproj) containing PInvoke calls into the DLL. All compiles fine. When I build, I would like to be able to add a reference from the csharp project to the cpp DLL project so that

How to separate managed and unmanaged DLLs in another directory

岁酱吖の 提交于 2019-11-26 14:47:24
问题 My Release folder is: MyApp.exe MyManagedDLL.dll NativeDLL.dll MyApp uses the managed dll which calls with pinvoke the native dll. I tried to move them to another subfolder folder and I referenced the managed dll again, when I run my app it says it can't find the NativeDLL.dll. How to fix that? 回答1: Windows has no idea that it needs to look in a subdirectory for the DLL. It will only look in a select few places for the DLL, starting from the folder that contains the EXE. Giving it a hard time

Difference between “managed” and “unmanaged”

时光总嘲笑我的痴心妄想 提交于 2019-11-26 12:42:00
I hear/read about it sometimes when talking about .NET, for example "managed code" and "unmanaged code" but I have no idea what they are and what are their differences. What are their difference, by definition? What are the consequences of using either of them? Does this distinction exist in .NET/Windows only? Managed Code Managed code is what Visual Basic .NET and C# compilers create. It runs on the CLR (Common Language Runtime), which, among other things, offers services like garbage collection, run-time type checking, and reference checking. So, think of it as, "My code is managed by the

Using C++ Class DLL in C# Application

倾然丶 夕夏残阳落幕 提交于 2019-11-26 11:41:38
I have an unmanaged C++ DLL which merely exports a single class (not COM...it's just a simple C++ class) as its interface. I want to use this class in C# but am told that it cannot merely be imported into C#. What is the right way to use this class in my C# application? ShuggyCoUk Simple way assuming class Foo: Create a C++/CLI project, call this FooWrapper. Make FooWrapper depend on the unmanaged dll (however you normally would). Create a managed class ManagedFoo which contains a single private instance field of type Foo*. provide public wrapping functions in ManagedFoo which forward on to

C# “Unmanaged Exports” [closed]

我的梦境 提交于 2019-11-26 09:02:05
问题 I\'ve been trying to use the extension \"Unmanaged Exports\" by Robert Giesecke in a Visual Studio 2010 pro/C# project. Yet, I can\'t make it work - when I check the compiled DLL for exports, the viewer (http://www.nirsoft.net/utils/dll_export_viewer.html) always comes up empty, no exports seem to be defined at all. I have all but copied the example and set build/config manager/active platform to x86. Can I somehow check if the MSBuild task that does all the magic is actually run or not? What

What is meant by “managed” vs “unmanaged” resources in .NET?

冷暖自知 提交于 2019-11-26 07:59:16
问题 What is meant by the terms managed resource and unmanaged resource in .NET? How do they come into the picture? 回答1: The term "unmanaged resource" is usually used to describe something not directly under the control of the garbage collector . For example, if you open a connection to a database server this will use resources on the server (for maintaining the connection) and possibly other non-.net resources on the client machine, if the provider isn't written entirely in managed code. This is