dllimport

Native loading works good. Loading from .net gives error Unable to load DLL 'my.dll': Invalid access to memory location

北城以北 提交于 2019-12-02 05:52:16
I'm trying to use native dll, using DllImport. And I receive such error. System.DllNotFoundException: Unable to load DLL 'my.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6) That dll loads normally when is called from native code (it is used from delphi app). But when I call it from .net code, it gives me exception above. I've read this link Windows Vista: Unable to load DLL 'x.dll': Invalid access to memory location. (DllNotFoundException) , but no solution helps. DEP, Administration rights are not the case. P.S. This situation occurs on Windows 2008 server. On

Pinning char[] on P/Invoke call

青春壹個敷衍的年華 提交于 2019-12-02 05:09:39
问题 I have object pool of char buffers and passing this buffer on P/Invoke call. Do i need pinning buffer before call or not? First approach: [DllImport("Name", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern void SomeMeth(char[] text, int size); public static string CallSomeMeth() { char[] buffer = CharBufferPool.Allocate(); SomeMeth(buffer, 4095); string result = new string(buffer, 0, Array.IndexOf(buffer, '\0')); CharBufferPool.Free(buffer);

Finding the class name of the On-Screen Keyboard?

﹥>﹥吖頭↗ 提交于 2019-12-02 04:45:50
I am attempting to use this code sample to control the Windows XP On-Screen Keyboard (OSK.exe) from a C# (.NET 3.5) Winforms application: [DllImport("User32.dll")]public static extern Int32 SetForegroundWindow(int hWnd); [DllImport("user32.dll")]public static extern int FindWindow(string lpClassName, string lpWindowName); private void BringToFront(string className,string CaptionName) { SetForegroundWindow(FindWindow(className,CaptionName)); } private void Form1_Load(object sender, EventArgs e) { BringToFront("Notepad", "Untitled - Notepad"); } How do I determine the accurate className? I

DllImport Unmanaged, Non .NET Dll to .NET Project Representing Char * and Void __StdCall

梦想的初衷 提交于 2019-12-02 04:22:26
问题 I have a DLL non .net and unmanaged written in Borland C++ that I need to import. It returns void and has the identifier __stdcall on the function. It also requires passing of char *. When I try to add it as a reference to my project in VS 2005, it returns an error of not valid assembly. How can I do this in C#? This what I currently have and it does not work: [DllImport ("Project1.dll", CallingConvention=CallingConvention.StdCall)] public static extern IntPtr CustomerForm (String caption);

Error C2491: Function declared in header and defined in C++

倖福魔咒の 提交于 2019-12-02 03:08:12
I have been trying to build a device adapter for a open-source software called Micro-manager to control a microscope and there are some problems that I am facing, there are these two files (one header and the other CPP) that are already present in the open source package of Micro-Manager. //MoudluleInterface.h #ifndef _MODULE_INTERFACE_H_ #define _MODULE_INTERFACE_H_ #ifdef WIN32 #ifdef MODULE_EXPORTS #define MODULE_API __declspec(dllexport) #else #define MODULE_API __declspec(dllimport) #endif #else #define MODULE_API #endif #define MM_MODULE_ERR_OK 1000 #define MM_MODULE_ERR_WRONG_INDEX 1001

Pointers in C# to Retrieve Reference From DllImport Function

人盡茶涼 提交于 2019-12-02 02:40:32
I am referencing a DLL in my C# project as follows: [DllImport("FeeCalculation.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] public static extern void FeeCalculation(string cin, string cout, string flimit, string frate, string fwindow, string fincrement, string fbird, string fparameter, string fvalidation, string fcoupon); The FeeCalculation function is exported as follows in the DLL: extern "C" __declspec(dllexport) void __stdcall FeeCalculation(char *cin, char *cout, char *flimit, char *frate, char *fwindow, char *fincrement, char *fbird, char *fparameter,

Pointers in C# to Retrieve Reference From DllImport Function

柔情痞子 提交于 2019-12-02 02:25:55
问题 I am referencing a DLL in my C# project as follows: [DllImport("FeeCalculation.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] public static extern void FeeCalculation(string cin, string cout, string flimit, string frate, string fwindow, string fincrement, string fbird, string fparameter, string fvalidation, string fcoupon); The FeeCalculation function is exported as follows in the DLL: extern "C" __declspec(dllexport) void __stdcall FeeCalculation(char *cin,

Call a C# method/function from a C++ DLL (which is loaded from C# with “Dllimport”)

北战南征 提交于 2019-12-02 02:23:34
It's a little hard to resume it in a single title, so here my situation. I'm building a C# application that loads a C++ library. I call functions from that C++ DLL. But I'd also like my C++ DLL to call functions from the C# application (that is importing/running it)... Here a piece of code to make it a little more comprehensive : // I'm importing functions from my native code [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)] public static extern int returnIntValue(int value); [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)] public static extern int

P/Invoking to Native DLL with Runtime Filename

江枫思渺然 提交于 2019-12-02 00:45:04
For versioning reasons it would be beneficial for me to be able to use p/invoke on a native C++ dll whose filename will be determined at runtime, as such: [DllImport(myDllFilename)] private static extern void MyInvokedMethod(); Unfortunately [DllImport] is an attribute and demands a constant expression. Are there any other options for getting around this error? I am aware I can use identically named files in different folders and load the right one at runtime, but being able to use differently named files would be ideal for my case. To achieve what you want you need to PInvoke several things (

Pinning char[] on P/Invoke call

一世执手 提交于 2019-12-01 23:45:26
I have object pool of char buffers and passing this buffer on P/Invoke call. Do i need pinning buffer before call or not? First approach: [DllImport("Name", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern void SomeMeth(char[] text, int size); public static string CallSomeMeth() { char[] buffer = CharBufferPool.Allocate(); SomeMeth(buffer, 4095); string result = new string(buffer, 0, Array.IndexOf(buffer, '\0')); CharBufferPool.Free(buffer); return result; } Second approach: [DllImport("Name", CharSet = CharSet.Unicode, CallingConvention =