Relative path to unmanaged DLL

Possible Duplicate: Specify the search path for DllImport in .NET I have an unmanaged DLL. For clearance, its a C++ dll that I want to use in my c# code. The problem is that its a windows app and user can install it in any directory of their choice. So I can't reference it with a static path and I couldn't find a way to give a relative path. Here is the code I tried : [DllImport

非托管DLL的相对路径

可能重复: 在.NET中指定DllImport的搜索路径 我有一个非托管DLL。 对于清除,它是一个我想在我的C#代码中使用的C ++ dll。 问题是,它的Windows应用程序和用户可以安装在他们选择的任何目录。 所以我不能用静态路径来引用它,而且我也找不到一个给出相对路径的方法。 这是我尝试的代码: [DllImport("mydll.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool SetDllDirectory(string lpPath

P/Invoke or C++/CLI for wrapping a C library

Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the rest of the project. Are there any objective reasons to prefer P/Invoke or C++/CLI for the interoperability underneath that API, in terms of robustness, maintainability, deployment, ...? The issues I could think of th

P / Invoke或C ++ / CLI封装C库

具有中等大小(40多个函数)的C API,需要从C#项目中调用。 这些函数在逻辑上分解成几个类,这些类将被呈现给项目的其余部分。 在稳健性,可维护性,部署等方面,是否有任何客观的理由来选择P / Invoke或C ++ / CLI来实现该API下的互操作性? 我能想到的问题可能是,但没有问题的是: C ++ / CLI将需要一个单独的程序集,P / Invoke类可以在主程序集中。 (我们已经有了多个程序集,无论如何都会有C dll,所以不是主要

Calling a static function from an extern function C++ DLL

I have written a C++ DLL with 2 extern "C" functions included within it as well as a static function which is called from within one of the extern functions. When I try to call the extern functions from C#, the one which calls the static function (also included in the DLL) I get a build warning ("Method, operator or accessort '...' is marked external and has no attributes

从外部函数C ++ DLL调用一个静态函数

我写了一个C ++ DLL,其中包含2个extern“C”函数,以及一个从其中一个extern函数中调用的静态函数。 当我尝试从C#中调用外部函数时,调用静态函数(也包含在DLL中)的函数会得到一个构建警告(“Method,operator或accessort'...''被标记为external,并且没有属性它考虑添加一个DllImport属性来指定外部实现)当我注释掉静态函数调用时,一切都会顺利编译,关于如何解决这个问题的任何想法?我还必须在静态函数中使

LINQPad: Attempting to use assembly that uses [DllImport] to access C++ dll

I added MyAssembly.dll as an additional reference to my query, and that works fine: I am able to use various classes from it with no trouble. One of the methods for one of the classes in MyAssembly.dll references another dll (Wrapper.dll). Wrapper.dll uses [DllImport] to access functionality in a C++ dll (C.dll): [DllImport("C.dll", CallingConvention = CallingConvention.StdCall, En

LINQPad:尝试使用使用[DllImport]访问C ++ dll的程序集

我添加MyAssembly.dll作为我的查询的额外参考,并且工作正常:我可以毫不费力地使用它的各种类。 其中一个MyAssembly.dll类的方法之一引用另一个DLL(Wrapper.dll)。 Wrapper.dll使用[DllImport]访问C ++ dll(C.dll)中的功能: [DllImport(“C.dll”,CallingConvention = CallingConvention.StdCall,EntryPoint =“CPlusPlusFunction”)]内部静态外部UInt32 _CPlusPlusFunction([MarshalAs(UnmanagedType.LPWStr)] st

Fail to load DLL in Windows 2008 R2 having full permissions control

I have developed an C# application that run very well in local. But there is a problem when i put on the server. The application uses a DLL library in his references (A.dll) and in a point of the execution the A.dll creates in the Temp directory another DLL (embedded in it, let's call it B.dll). But when the A.dll try to load the B.dll an exception is threw: system.invalidoperationexcep

未能在具有完全权限控制的Windows 2008 R2中加载DLL

我开发了一个在本地运行得非常好的C#应用​​程序。 但是当我穿上服务器时出现问题。 应用程序在其引用(A.dll)中使用DLL库,并在A.dll在Temp目录中创建另一个DLL(嵌入其中,让我们称之为B.dll)的执行点中。 但是,当A.dll尝试加载B.dll时,会抛出一个异常: system.invalidoperationexception: failed to load B.dll 我没有访问DLL的来源,是库。 所以回顾一下: 该进程拥有文件和路径的完全控制权限。 (cheked

Using DllImport to load unmanaged dll into managed application

In my project I have an unmanaged native C++ dll and a C# application. I am trying to import a function from the unmanaged dll using DllImport but I keep getting a DllNotFoundException. Here is my code that calls the DLL. using System.Runtime.InteropServices; namespace TestApp { public delegate void UpdateDelegate(string s); class Program { [DllImport("CGPUnmanagedLibrary.dll")]

使用DllImport将非托管dll加载到托管应用程序中

在我的项目中,我有一个非托管的本机C ++ dll和一个C#应用程序。 我试图从使用DllImport的非托管dll导入函数,但我不断收到DllNotFoundException。 这是我调用DLL的代码。 using System.Runtime.InteropServices; namespace TestApp { public delegate void UpdateDelegate(string s); class Program { [DllImport("CGPUnmanagedLibrary.dll")] internal static extern int parse_raw_gsod_file( [Mars

Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

I have dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method i try to load my dll i get an error: Unable to load DLL 'MyOwn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) I have read and tried severa solutions i have found on the internet. Nothing works.. I have tried using following methods: [DllI

无法加载DLL(无法找到模块HRESULT:0x8007007E)

我有我需要在.NET 4.0应用程序中使用的非托管C ++ API代码的dll库。 但是,我尝试加载我的DLL的每一个方法,我得到一个错误: 无法加载DLL'MyOwn.dll':无法找到指定的模块。 (来自HRESULT的异常:0x8007007E) 我已阅读并尝试了在互联网上找到的severa解决方案。 什么都没有 我曾尝试使用以下方法: [DllImport("MyOwn.dll", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs((UnmanagedT

How to call win32 dll in windows 7

From within a C# application(Visual Studio 2008) i am calling a win32 dll using DllImport. Everything works fine in Windows XP. However when i use the same exe and dll in Windows 7, the win32 dll fails to get loaded. Do i need to write any extra code to invoke a win32 dll from Windows 7 ? Before building the C# program, make sure that in Visual studio Configuration Manager you choose "x

如何在Windows 7中调用win32 dll

从C#应用程序(Visual Studio 2008)中,我使用DllImport调用win32 dll。 在Windows XP中一切正常。 但是,当我在Windows 7中使用相同的exe和dll时,win32 dll无法加载。 我是否需要编写任何额外的代码来从Windows 7调用win32 dll? 在构建C#程序之前,请确保在Visual Studio Configuration Manager中选择“x86”而不是“任何CPU”作为平台。 如果选择任何CPU,则C#应用程序将在Windows 7中以64位进程运行,并尝试将32位win

Using C++ native dll in .Net External component has thrown an exception

I'm trying to use a native C++ dll in C# and am getting the "External component has thrown an exception" with an error code of -2147467259. C#: [DllImport(@"MyDLL.dll", CharSet = CharSet.Auto)] public static extern string MyFunction([MarshalAs(UnmanagedType.LPStr)] StringBuilder input); C++: __declspec(dllexport) char * __stdcall MyFunction(const char* inputPtr); The function

在.Net外部组件中使用C ++本机DLL会引发异常

我试图在C#中使用本机C ++ dll,并得到“外部组件引发异常”,错误代码为-2147467259。 C#: [DllImport(@"MyDLL.dll", CharSet = CharSet.Auto)] public static extern string MyFunction([MarshalAs(UnmanagedType.LPStr)] StringBuilder input); C ++: __declspec(dllexport) char * __stdcall MyFunction(const char* inputPtr); 该函数在C ++中工作得很好。 我怎样才能追踪这个错误? 我曾尝试使用字符串和字符串

import c++ dll to windows phone project

I'm new on windows phone developement and i have one problem that i don't know how to resolve.... the problem is.... i have a c++ project that i had complided with visual c++ 2010 and this create one dll with code compiled... so i know that C# import dll libraries but when i add refrences it's make this error "Unable to retrieve assembly fullname ""Parameter name:

将c ++ dll导入windows phone项目

我是新的Windows手机开发,我有一个问题,我不知道如何解决.... 问题是.... 我有一个c ++项目,我已经与visual c ++ 2010 complided,这创建一个DLL编译代码... 所以我知道C#导入dll库,但当我添加refrences它使这个错误“无法检索程序集全名”“参数名称:AssemblyPath”,我不知道它是什么意思... 我在谷歌搜索,我发现一种方法导入c + + dll manualy与DllImport和调用外部方法...导致一个错误,因为它没有找到dll位置...