unmanaged

Performance of Calling Unmanaged .dll from C#

How long is the typical overhead added by calling a .dll written in C++ from a C# application using the following syntax? [DllImport("abc.dll", EntryPoint = "xcFoo", CallingConvention = CallingConvention.Cdecl)] public extern static Result Foo(out IntPtr session, [MarshalAs(UnmanagedType.FunctionPtr)]ObjectCallback callb...

Passing c# string to unmanaged c++ DLL

Hi All, I have a simple application that loads an unmanaged dll and passes a few string values to it from C#. But in the C++ dll application, I receive an exception :: Tried to access a read/write protected memory. My DLL Import looks like this: [DllImport("X.dll", CallingConvention = CallingConvention.Cdecl) ] public static extern int...

How do I return a char* array from a clr assembly?

I have a simple managed C++ assembly which I am providing unmanaged wrappers for some static methods I have in a C# assembly. One of these methods returns a string which I have converted to a "const char*" type in the C++ assembly. The trouble I am having is that when I load this dll from an unmanaged source, I get bad data back in the p...

How do I import and call unmanaged C dll with ansi string "char *" pointer string from VB.net?

I have written my own function, which in C would be declared like this, using standard Win32 calling conventions: int Thing( char * command, char * buffer, int * BufSize); I have the following amount of VB figured out, which should import the dll and call this function, wrapping it up to make it easy to call Thing("CommandHere",GetDat...

Is Classic ADO still viable for a mixed managed/unmanaged App?

We have a complex architecture with much logic in unmanaged code that needs database access. Currently this is via ODBC drivers and MFC classes and we're considering the issues of migrating our abstraction layer to use ADO or ADO.Net. In the latter case we'd have to be pushing database logic back up into the .Net layer. I'm trying to d...

MEF - Modify execution if one plugin fails

Hi! I'm using MEF for a plugin-system to my application. The flow goes like this: Run all Pre-plugins Run all Core-plugins Run all Post-plugins For example, if a plugin in the Core execution fails, i don't want to run certain post plugins. What would be the best way to achieve this? Hope my question is clear, otherwise please tell ...

How can I declare constant strings for use in both an unmanaged C++ dll and in a C# application?

Curently I'm passing my const string values up from my C++ into my C# at startup via a callback, but I'm wondering if there's a way of defining them in a C++ header file that I can then also refer to in C#. I already do this with enums as they are easy. I include a file in both my C++ library project (via a .h file with a pragma once at...

IIS7 Modules - managed or native?

Hi all, as the old ISAPI filters are going to die sooner or later, I want to rewrite an old ISAPI filter that was used in IIS 6 into a module for use in IIS 7. The module will be used globally, meaning it will be used within each site, on a Windows Server 2008 R2 with IIS 7.5 installed, that will host several thousand web sites and manag...

Listing functions of an unmanaged DLL at runtime in c#

Hi, Is it possible to obtain a list of functions declared in an unmanaged DLL? I want to create this list in a c# program. Using dumpbin or System.Reflection.Assembly is not possible. Thanks ...

Using unmanaged code from managed code

Hi I have my project developed in MFC which is unmnaged code. Now i need to create a similar application in C#, by reusing most of the MFC classes. Is it possible to directly export class/struct/enum from MFC dll, so that i can import it in my C# using dllimport and use it.? ...

SuppressUnmanagedCodeSecurity At Class Level

If I add the [SuppressUnmanagedCodeSecurity()] attribute to a class, is it equivalent to adding it to each function in the class? ...

Blittable Vs. Non-Blittable in IL

I'm trying to make sure that my Managed to Unmanaged calls are optimized. Is there a quick way to see by looking at the IL if any non-blittable types have accidentally gotten into my pinvoke calls? I tried just writing two unmanaged functions in a .dll, one that uses bool (which is non-blittable) and one that uses ints. But I didn't s...

Blittable Value Types

Here is a list of blittable types. It contains Int32 and Int64. But I don't see just plain "int" on the list. How does C# treat the plain "int" type? Does it just get replaced with Int32 or Int64 depending on the system? Or is there a subtle difference? Will using "int" ever cause a performance hit for marshalling? ...

copy unsigned array from managed to unmanaged

Marshal.copy allows for signed data types only, but I have a giant array of uint16 to pass to IPP code. Any ideas ? unsafe for looping on it seems wrong ... ...

StackOverflow Exception in Umanaged Dll When Called from Managed DLL

My question is similar to this one here, but there are some difference. I have a fortran dll as the backend, and a C# exe as the front end. I use PInvoke to pass data between them. There are 22 parameters between the C# and the fortran code. And some of them are integer, double, pointers ( C# pointers), array and whatnot. So it's a m...

Converting unmanaged C++ code from 32 bit to 64 bit

Hi, I have an unmanaged C++ 32 bit application that produces a dll. Now, I want to build it for 64 bit system. My development system is 32 bit. It uses oledb.lib activeds.lib adsiid.lib ws2_32.lib libraries to build the dll. What I have done so far is : Changed the configuration settings and set the Active solution platform to x64. It b...

How can I detect which callback from an unmanaged dll causes a protected memory exception?

I get a protected memory exception, but how can I know which call caused it, and why the callback function has moved? All the calls to unmanaged code are done in the same class as the callback functions, so I suppose that the addresses should not change, or am I totally wrong here? ...

Dependency Walker Not Showing All the Depended Dll

I have a fortran dll, and I want to know the assemblies that it depends on for redistribution purpose. One thing I found out is that the dependency walker doesn't show all of the dependencies, i.e, there are some dlls that my assembly is dependent on, but dependency walker doesn't show it out. An example would be a dll that makes use...

Converting C# void* to byte[]

In C#, I need to write T[] to a stream, ideally without any additional buffers. I have a dynamic code that converts T[] (where T is a no-objects struct) to a void* and fixes it in memory, and that works great. When the stream was a file, I could use native Windows API to pass the void * directly, but now I need to write to a generic Stre...

Using unmanaged code, how can I find a type that has a given custom attribute assigned to it?

I had thought I could enumerate the types using IMetaDataImport.EnumTypeDefs and for each of the tokens returned, call IMetaDataImport.EnumCustomAttributes. This works, in so much as I get an array of mdCustomAttribute tokens. Using these tokens I can get a metadata token representing the Type of the returned custom attribute, by calli...