How to use [DllImport(“”)] in C#?

You can’t declare an extern local method inside of a method, or any other method with an attribute. Move your DLL import into the class: using System.Runtime.InteropServices; public class WindowHandling { [DllImport(“User32.dll”)] public static extern int SetForegroundWindow(IntPtr point); public void ActivateTargetApplication(string processName, List<string> barcodesList) { Process p = Process.Start(“notepad++.exe”); p.WaitForInputIdle(); IntPtr h = p.MainWindowHandle; SetForegroundWindow(h); … Read more

Is there any native DLL export functions viewer? [duplicate]

dumpbin from the Visual Studio command prompt: dumpbin /exports csp.dll Example of output: Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file csp.dll File Type: DLL Section contains the following exports for CSP.dll 00000000 characteristics 3B1D0B77 time date stamp Tue Jun 05 12:40:23 2001 0.00 version 1 ordinal … Read more

How to use a class in DLL?

If you use run time dynamic linking (uses LoadLibrary to load the dll) you cannot access the class directly, you need to declare a interface for your class and create a function that returns a instance of this class, like this: class ISDLConsole { public: virtual void getInfo(int,int) = 0; virtual void initConsole(char*, char*, SDL_Surface*, … Read more

How to build a DLL version of libjpeg 9b?

Published builds (static / dynamic) on [GitHub]: CristiFati/Prebuilt-Binaries – (master) Prebuilt-Binaries/LibJPEG. Like almost all of the nowadays software, LibJPEG is also hosted on [GitHub]: winlibs/libjpeg – libjpeg-9b. I downloaded it from both places, did a comparison and only few minor differences (out of which none in the source code) popped up. I’m going to explain … Read more

ADODB.Parameters error ‘800a0e7c’ Parameter object is improperly defined. Inconsistent or incomplete information was provided

Common occurrence is likely you do not have adVarChar defined, so the CreateParameter() method is “improperly defined”. This is just an example of one of the many named constants found in the ADODB Library. A messy approach to dealing with this is to just define the value yourself something like; Const adVarChar = 200 The … Read more

Using a 32bit or 64bit dll in C# DllImport

I’ve found the simplest way to do this is to import the two methods with different names, and calling the right one. The DLL won’t be loaded until the call is made so it’s fine: [DllImport(“MyDll32.dll”, EntryPoint = “Func1”, CallingConvention = CallingConvention.Cdecl)] private static extern int Func1_32(int var1, int var2); [DllImport(“MyDll64.dll”, EntryPoint = “Func1”, CallingConvention … Read more

Unload a DLL loaded using DllImport

The most reliable way to unload an unmanaged DLL from a process that got loaded by a [DllImport] pinvoke declaration is to load it yourself, again, by pinvoking LoadLibrary(). That gives you a reliable handle to the DLL and works correctly even if the module name of the DLL is ambiguous. It doesn’t have any … Read more