dllimport

Specify the search path for DllImport in .NET

落花浮王杯 提交于 2019-12-17 02:12:06
问题 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 manifest file to avoid dynamic loading and dynamic invocation? 回答1: Call SetDllDirectory with your additional DLL paths before you call into the imported

Specify the search path for DllImport in .NET

丶灬走出姿态 提交于 2019-12-17 02:12:01
问题 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 manifest file to avoid dynamic loading and dynamic invocation? 回答1: Call SetDllDirectory with your additional DLL paths before you call into the imported

Unable to load DLL in WPF C# application

戏子无情 提交于 2019-12-14 04:02:22
问题 I get following error message (VS2010) when running in debug mode my C# WPF appliction: "Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" The code where this error occurs is (see hDevEnum): namespace Imperx.FLExGrabber { public class Enumerator:IEnumerator { private IntPtr hDevEnum; VCECLB_EnumData enumData; /// Default constructor public Enumerator() { enumData.cbSize = (UInt32)Marshal.SizeOf(enumData); // Open enumerator handle

using C++ DLL in C# windows application:Getting error “Entry point not found”

半腔热情 提交于 2019-12-13 19:35:27
问题 I am new to using C++ libraries in C# and also to the C++ programming in general. I have a DLL built from a C++ code which I believe is a 'managed' code as the name of the DLL is "TestManaged.dll". I am not 100% sure if the dll/C++ code is managed/unmanaged. I want to use classes and methods of this DLL in my C# windows forms application code. There are multiple classes in this DLL. When I chekced these classes and methods inside those classes in Object Browser , all of them have Public

DllImport, Char*& and StringBuilder C/C#

孤街浪徒 提交于 2019-12-13 15:05:41
问题 I have a problem, I tried to look at almost all the poster solutions, unsuccessful to find a suitable one. The question is easy, Want to have a return string from unmanaged C code in my managed C#. The c function is: extern "C" __declspec(dllexport) int process_batch (char *&result); and in C# I imported the DLL: [DllImport("mydll.dll")] public static extern IntPtr process_batch(StringBuilder result); I run, but the return value in my StringBuilder is a 7-8 character string of non-sense! (I

An attempt was made to load a program with an incorrect format

人走茶凉 提交于 2019-12-13 08:18:49
问题 I am using C# loading C++ dll, and got this error: "An unhandled exception of type 'System.BadImageFormatException' occurred in MyApp.exe" "Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8057000B) I could not figure out why. The C++ dll was generated using vs2012 wizard, win32 application, dll with pre-head. It is built with x64 option. Here is the code: // MyNativeDLL.cpp : Defines the exported functions for the DLL

Am I Importing a SQLite3 C Function Correctly into C#

≡放荡痞女 提交于 2019-12-13 05:11:05
问题 I am attempting to import a SQLite3 C function inside C# but I am unsure I have imported it correctly, ie, that the function parameter data types are correct and that the function is being used correctly? The function is being used to insert a images data(.png) into a Sqlite3 table. This is the actual C implementation from the SQLite website: int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); This is my import in C#: [DllImport("sqlite3", EntryPoint = "sqlite3_bind

import VS C++ DLL in C++ Builder

我的未来我决定 提交于 2019-12-13 05:04:19
问题 I created a project using C++/CLI in Visual Studio 2012. The GUI was made in C++ Builder XE2 and I would like to import the generated DLL from VS C++ 2012 but I was not able to import it correctly. HINSTANCE load = LoadLibrary(library); if (!load) ShowMessage("Error importing the library"); Unfortunately when I run the code after I use the LoadLibrary function the variable load is NULL. Any help? I unsterstood that I need to use some utilities from the C++ Builder to convert the DLL generated

Use C Library in .NET

不打扰是莪最后的温柔 提交于 2019-12-13 03:20:58
问题 I need to use the C library in a C# project. How can I do? To be more specific: for reasons of efficiency I need to use the strtod function to extract double values from a string (like this "9.63074,9.63074 -5.55708e-006 0 ,0 1477.78"). If you have suggestions about how to optimize this operation do not be shy, but the main question remains that specified by title. 回答1: I think it very unlikely that p/invoking to strtod would be more efficient than a pure C# solution. There is an overhead in

DllImport with different entry points (different DLLs for the same import in different projects)

一曲冷凌霜 提交于 2019-12-13 03:11:59
问题 As a follow-up to my recent question about .NET Compact Framework debugging, I am currently trying to use OpenGL ES from both a .NET Compact Framework and a .NET Framework application. I use this wrapper, which has been created for OpenGL ES and imports from libGLES_CM.dll. To make debugging easier, I created a .NET Framework application, recreated the import project for OpenGL ES and EGL with the same files (just building for Desktop framework), created constants for the DLL names so they'll