dllimport

SharePoint fails to load a C++ DLL on Windows 2008

I have a SharePoint DLL that does some licensing things and as part of the code it uses an external C++ DLL to get the serial number of the hardisk. When I run this application on Windows Server 2003 it works fine, but on Windows Server 2008 the whole site (loaded on load) crashes and resets continually. This is not Windows Server 2008 ...

PInvokeStackImbalance C# call to unmanaged C++ function

After switching to VS2010, the managed debug assistant is displaying an error about an unbalanced stack from a call to an unmanaged C++ function from a C# application. The usuals suspects don't seem to be causing the issue. Is there something else I should check? The VS2008 built C++ dll and C# application never had a problem, no weird ...

P/Invoke dynamic DLL search path

I have an existing app which P/Invokes to a DLL residing in the same directory as the app itself. Now (due to the fact that Canon produces one of the crappiest API's around) I need to support two versions of this API and determine at run-time which one I should use (old or new). Since the DLLs have the same name (the first one loads oth...

Tool for Importing C++ DLL

My company uses a third-party C++ DLL which is updated periodically. I've been manually creating C# DLLImport statements, but in this last update the number of functions nearly doubled. Is there any tool (preferably free) that will create C# DLLImport's from an unmanaged C++ .dll or .lib file? (The DLL exports decorated C++ functions,...

GetDC() DllImport for x64 apps

If you make a little research on the internet you'll see many DLLImport styles for this user32.dll function: HDC GetDC(HWND hWnd); The question is: what type is more appropriate for .NET x64 apps (either compiled with the Platform target as AnyCPU on a x64 machine or specifically as x64)? IntPtr for example grows to a size of 8 on a x...

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

Unresolved external symbol

I have two WIN32 DLL projects in the solution, main.dll should call a function in mgn.dll. mgn.dll has mgn.h header file: #ifdef MGN_EXPORTS #define MGN_API __declspec(dllexport) #else #define MGN_API __declspec(dllimport) #endif extern "C" bool MGN_API AttachMGN(void); and mgn.cpp source file: #include "stdafx.h" #include "mgn.h" ...

Wrong Library Imported via #pragma comment(lib, ...) in Visual C++

I'm using Visual Studio 2008. I have a DLL and a test program EXE. There is a header file for the DLL that contains this: #ifdef _DEBUG #pragma comment(lib, "FooD.lib") #else #pragma comment(lib, "Foo.lib") #endif The intent is to dynamically link to FooD.dll through the FooD.lib import library, for a debug build, and to Foo...

Alternate cause of BadImageFormatException in .NET Assembly?

I'm working on a .NET 3.5 console application in C# which uses a VC++ unmanaged DLL. It ran without a problem when I worked on it a few weeks ago, but I'm coming back to it today and am now getting a BadImageFormatException ("An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)). My develo...

Dll execute during MSI execution(Installer)

I created an MSI for my application and i want my dll to execute during installation of this MSI. How can i add my dll to MSI. I read something on ORCA but getting error. Can anyone help to add my dll to msi using orca. My dll contain a message box and registry entry ...

how to access char*** from dll import in C#

I have a function in win32 dll with signature as: void func1(int a, char*** outData) int a --> input parameter char*** outData --> output parameter - pointer to array of char strings Any idea how to access this in C# using dll import & what should be the signature. ...

C# CreatePipe() -> Protected memory error

Hi all, I trying to create a pipe using C#. The code is quite simple but I get a error saying "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Here the COMPLETE code of my form : public partial class Form1 : Form { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastErr...

Create an instance of an exported C++ class from Delphi

I followed an excellent article by Rudy Velthuis about using C++ classes in DLL's. Everything was golden, except that I need access to some classes that do not have corresponding factories in the C++ DLL. How can I construct an instance of a class in the DLL? The classes in question are defined as class __declspec(dllexport) exampleC...

DllImport and char*

I have a method I want to import from a DLL and it has a signature of: BOOL GetDriveLetter(OUT char* DriveLetter) I've tried [DllImport("mydll.dll")] public static extern bool GetDriveLetter(byte[] DriveLetter); and [DllImport("mydll.dll")] public static extern bool GetDriveLetter(StringBuilder DriveLetter); but...

Replacing the Import Table in PE file by standart LoadLibrary...

Hello. I have an executable (PE) file that load a dll file as represented in the Import table... let say: PEFile.exe Modules.dll my question is how can i remove Modules.dll's import_descriptor from the imports and do its work by loadLibrary without the rely on the import table and without destroy the file???... My bigger problem his i...

System.AccessViolation in DllImport method after redeploy

Hi Everyone, My environment: Windows 2003, VS 2008, .NET 3.5 C# .NET application. During loading my application I call method from C++ dll (Knowl.dll) through my third-party dll library (Common.dll) written in C#. After first deploy (from VS to Developing server) evrything works fine. Then I stops Developing Server, doesn't any changes ...

Trying to create a .NET DLL to be used with Non-.NET Application

I am trying to create a .NET DLL so I can use the cryptographic functions with my non .NET application. I have created a class library so far with this code: namespace AESEncryption { public class EncryptDecrypt { private static readonly byte[] optionalEntropy = { 0x21, 0x05, 0x07, 0x08, 0x27, 0x02, 0x23, 0x36, 0x45, 0x...

Calling unmanaged c++ code in C# Mixed with STL

Hey, I want to call unmanaged c++ code in C# The function interface is like following(I simplified it to make it easy to understand) Face genMesh(int param1, int param2); Face is a struct defined as: struct Face{ vector<float> nodes; vector<int> indexs; } I googled and read the MSDN docs found ways to call simple c/c++ un...

unable to find an entry point named 'interlockedexchange'

Hi , I built an application in c# vs2005 .net . Everything works fine when i run the application in win 32 bit, But when running the application in win 64 it crashes while trying to call the pinvoke interlockedexchange(which is within the kernel32.dll) function . This is the exception : unable to find an entry point named 'interlocked...

Use one single DLL library to import other libraries at runtime

I am writing a Win32 DLL library that can be redistributed. I am using different versions of the windows API because I want to support Windows 7 functions, but still have support for Windows 2000 (with some function disabled). What I have currently is MyLib2000.dll, MyLibXP.dll, and MyLibVista.dll, and my application chooses which librar...