unmanaged

Reverse PInvoke and create a full unmanaged C# program

I know this is a strange question but the idea is simple: I prefer C# syntax rather than C++: -Setters and getters directly inside a property -interfaces -foreach statement -possibility to declare an implicit cast operator other small things... What I really don't know is if is possible to import a c++ dll (expecially std libraries) in...

using C function in C#

i have a dll, built with mingw one of the header files contains this: extern "C" { int get_mac_address(char * mac); //the function returns a mac address in the char * mac } I use this dll in another c++ app, built using Visual C++ (2008SP1), not managed, but plain c++ (simply include the header, and call the function) But now I ha...

How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInfo ?

Hello, I need to call unmanaged COM code from C#.NET. By Loading unmanaged COM Type libraries from (LoadTypeLibEx), I am able to iterate over all exposed types by COM TLB. Now I need to call those exposed methods at run time by knowing their addresses or by accessing some how COM vtable's starting address and by applying indexing for ge...

How do I handle freeing unmanaged structures on application close?

I have a C# project in which i use several unmanaged C++ functions. More so, I also have static IntPtr that I use as parameters for those functions. I know that whenever I use them, I should implement IDisposable in that class and use a destructor to invoke the Dispose method, where I free the used IntPtr, as is said in the MSDN page. p...

Method of getting text on a windows form ( unmanaged C++ project )

I'm in the process of learning C++. I've created a boilerplate Win32 app within VC++ 2008. I've studied through the code and am ready do do a bit of experimenting. I thought it would be cool to print all the windows messages received in the message loop to the form created via the boilerplate code. I for the life of me, can't figure out ...

Handling exception from unmanaged dll in C#

Hello. I have the following function written in C# public static string GetNominativeDeclension(string surnameNamePatronimic) { if(surnameNamePatronimic == null) throw new ArgumentNullException("surnameNamePatronimic"); IntPtr[] ptrs = null; try { ptrs = StringsToIntPtrArray(surnameNamePatronimic); int resultLen = M...

Handling exception from unmanaged dll in C#

Hello. I have the following function written in C# public static string GetNominativeDeclension(string surnameNamePatronimic) { if(surnameNamePatronimic == null) throw new ArgumentNullException("surnameNamePatronimic"); IntPtr[] ptrs = null; try { ptrs = StringsToIntPtrArray(surnameNamePatronimic); int resultLen = M...

Unable to create unmanaged object using new keyword in managed C++

Hi all, I've created a class with a boost::unordered_map as a member, Linkage.h #ifndef LINKAGE_H #define LINKAGE_H #include <boost/unordered_map.hpp> class Linkage { private: boost::unordered_map<int, int> m_IOMap; public: .... }; Linkage.cpp #include "stdafx.h" ... // methods and in the managed side of C++, I t...

How to create a step by step wizard in C++ (with unmanaged code) in Visual Studio 2010

I would like to build a small wizard in C++ with no dependencies on any framework. Apparently, is really simple, but I don't know where to start. Can you point me to good information (tutorials, etc) on it. Should I use MFC Application or a Win32 project? Is there any step by step guide ? I'm using VS 2010. The majority of info I'd f...

How do I launch a winforms form from a DLL correctly?

There's another question similar to mine, but I wanted to gather some specifics: I want to create a DLL that is called from unmanaged code. When the unmanaged functions are called in the DLL, I want to collect information and show it in a kind of form. What I'd like to do is, when DllMain() is called, and the reason is DLL_PROCESS_A...

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

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

Calling 32 bit unmanaged dlls from C# randomly failing

Hi, I'm having an issue when calling 32 bit delphi dll's from c# web site. The code generally runs fine, but occasionally I get an error Unable to load DLL '': The specified module could not be found. (Exception from HRESULT: 0x8007007E). This issue persists until I recycle the app pool for the site, and then it works fine again. On t...

Do COM Dll References Require Manual Disposal? If so, How?

I have written some code in VB that verifies that a particular port in the Windows Firewall is open, and opens one otherwise. The code uses references to three COM DLLs. I wrote a WindowsFirewall class, which Imports the primary namespace defined by the DLLs. Within members of the WindowsFirewall class I construct some of the types de...

What .NET UnmanagedType is Unicode (UTF-16)?

I am packing bytes into a struct, and some of them correspond to a Unicode string. The following works fine for an ASCII string: [StructLayout(LayoutKind.Sequential)] private struct PacketBytes { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string MyString; } I assumed that I could do [StructLayout(LayoutKind....

I get an Access Denied error when calling LsaQueryInformationPolicy(), and I'm an admin

I get this error return whether I try LsaQueryInformationPolicy() on the local host or on some other machine in the domain. The flags I use for LsaOpenPolicy() are POLICY_LOOKUP_NAMES | POLICY_VIEW_LOCAL_INFORMATION but I also tried POLICY_LOOKUP_NAMES | POLICY_VIEW_LOCAL_INFORMATION | READ_CONTROL without success. The user I'm logged i...

Is it possible to call unmanaged code using C# reflection from managed code ?

Hi all, Is it possible using reflection and C# .NET to call dynamicly different function (with arguments) written in C or C++ before .NET came(unmanaged code) ? And smole C# example if possible would be appreciated! Thanks! Br, Milan. ...

Call c++ library from c#

Hello All, This question might seem a repeat of previous ones. I have read through a series of posts, but not completely clear for my situation. I have a c++ library which is created using momentics IDE. I have to be able to use this library into a c# project. Someone had been working on this project before being handed over to me. Cu...

Unmanaged Code calling leads to heavy memory leak!!

Maybe I need change the title as "Unmanaged Code calling leads to heavy memory leak!" The leak is around 30M/hour I think maybe I need complete my code here because the memory leak maybe not from a static string whereas my real code derive this string from external device (see new code attached). so I handle also unmanaged code. Could ...

Set DFS Link Permission with C#

Hi I have to set permissions on a DFS Link with C#. (For adding a DFS Link I used the method NetDfsAdd from the NetApi32.dll. ) After a while searching I found the MSDN Article[0] about NetDfsSetInfo and it describes that I can use this function to set the permissions. But I am a bit confused about DFS_INFO_107 Structure[1] and SECURIT...

Performance of Managed C++ Vs UnManaged/native C++

I am writing a very high performance application that handles and processes hundreds of events every millisecond. Is Unmanaged C++ faster than managed c++? and why? Managed C++ deals with CLR instead of OS and CLR takes care of memory management, which simplifies the code and is probably also more efficient than code written by "a pro...