dllimport

BadImageFormatException when loading 32 bit DLL, target is x86

I have a DLL (FreeType) which is certainly 32-bit (header: IMAGE_FILE_MACHINE_I386). I want to use it from C# code, using DllImport. Target of my application is x86, IntPtr.Size is 4, process is 32-bit. But I get BadImageFormatException (Exception from HRESULT: 0x8007000B). What can be wrong? Of course I use 64-bit Windows 7. ...

DLL takes forever to load in JNI class

Hi, I'm working with a jni application that loads a dll library, but the load of it is taking too long. The dll is in the path. As a relevant informat, this dll depends on other oracle dlls that are also in the path. System.loadLibrary("exmaple.dll"); Do you have any idea why the load never ends? ...

How to wrap two unmannaged C++ functions into two managed C# functions?

I've got two unmanaged C++ functions, Compress and Decompress. The arguments and returns go as followed: unsigned char* Compress (unsigned char*,int) unsigned char* Decompress (unsigned char*,int) Where all uchars are arrays of uchars. Could someone please help me lay out a way to convert these into managed C# code using the Byte[] a...

Accessing "Mapi32.dll" with C#. [not solved]

Hello, I am using VS 2008 C# Windows Application. I have this DLL Import I am trying to use. [DllImport("Mapi32.dll", PreserveSig = true)] private static extern void WrapCompressedRTFStream( [MarshalAs(UnmanagedType.Interface)] UCOMIStream lpCompressedRTFStream, uint ulflags, [MarshalAs(UnmanagedType.Interface)] out UCOMIStream lpUnco...

How to call functions inside a C dll which take pointers as arguments from C#

Hi people, this is my first post here! I'm trying to make a windows forms program using C# which will use a precompiled C library. It will access a smart card and provide output from it. For the library, I have a .dll, .lib and .h and no source. In the .h file there are several structs defined. Most interesting functions of the .dll exp...

using WrapCompressedRTFStream in C#

Hello, I am rewording this question: Csharp C# visual studio 2008 How do I use the WrapCompressedRTFStream when using DLLImport with mapi32.dll? Sample of code to import the WrapCompressedRTFStream method. (I found this, I did not figure this part out) [DllImport("Mapi32.dll", PreserveSig = true)] private static extern void...

Using custom dll in Qt Application

First, my compiler and OS: Qt Creator 1.3 Qt 4.6 (32 bit) Windows 7 Ultimate I want to learn how to create and import a dll in Qt. I've created a *.dll file using Qt Creator, called Shared1.dll which contains nothing but an empty class named Shared1. Now I'd like to use Shared1 class in another Qt project. How can I do that? Thanks ...

Unmanaged DLL in C# Web Service

Hi Guys, please help με as I am new into accessing an unmanaged DLL from C#.. I have a large unmanaged DLL in C++ and I am trying to access the DLL's classes and functions from a C# Web Service. I have seen many examples how to use DLLImport, but for some reason I am stuck with my very first wrapper method spending many hours with no l...

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

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

Specify the search path for DllImport in .NET

Is there a way to specify the paths to be searched for a given assembly that is imported with DllImport? [DllImport("MyDll.dll")] static extern void Func(); This will search for the dll in the app dir and in the PATH environment variable. But at times the dll will be placed elsewhere. Can this information be specified in app.config or...

C# - Possible to use IOCTL

I'm trying to code for a Point Of Sale system which allows for a "Cash Drawer" attachment. Code is provided in the manual for opening the cash drawer (in C++ using IOCTL). Since I am coding in C# .NET, is it possible to perform something similar from within C# or will I have to write some unmanaged code? Am I able to get a handle to "...

How to find a path to a native library loaded using DllImport in .NET?

Is there a way to find the path to a native dll loaded with DllImport? The only thing that comes to my mind is a series of calls: LoadLibrary(), GetModuleFileName() and FreeLibrary(). ...

How to call a C++ function that takes a reference from C# code

HI, I have a C++ function like the following: int ShowJob(const JobData& data); How does this translate to a DLLImport statement which I can use to call the function from C#? ...

Importing specific ( in my case - Themes.ThemesService.ThemesEnabled ) function / procedure in runetime in Delphi

Hi again :) I think subject tells everything ... I need this method only. No need to waste about 6Mb of included unit if only thing I need is one method from that unit ( Themes ) ... I was thinking of UxTheme unit, but it did not contain proper function. What Windows DLL do I need to import and what API function this method stands for...

P/Invoke a Function Passed a StringBuilder

in a C# file i have a class Archiver { [DllImport("Archiver.dll")] public static extern void archive(string data, StringBuilder response); } string data is an input, and StringBuilder response is where the function writes something the archive function prototype (written in C) looks like this: void archive(char * dataChr, ch...

how to call a C++ dll from C# windows application project

I have created a dll in C++ using a Class Library project in Visual Studio. I need to call a method in the dll from a C# application. I got to know there are 2 approches. One is to add the dll project reference to C# project or use DllExport to export method. However when I tried in both ways it always gives the following error when t...

C# - calling ext. DLL function containing Delphi "variant record" parameter

Hello, In external (Delphi-created) DLL I've got the following function that I need to call from C# application. function ReadMsg(handle: longword; var Msg: TRxMsg): longword; stdcall; external 'MyDll.dll' name 'ReadMsg'; The "TRxMsg" type is variant record, defined as follows: TRxMsg = record case TypeMsg: byte of 1: (a...

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

Using C++ DLL in C# project

Hello, I got a C++ dll which has to be integrated in a C# project. I think I found the correct way to do it, but calling the dll gives me this error: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) This is the function in the dll: extern long FAR PAS...