dllimport

how to use RegisterHotKey() in C#? [duplicate]

血红的双手。 提交于 2019-11-28 03:17:16
问题 This question already has an answer here: Global hotkey in console application 4 answers I'm trying register a hot key, I'm translating this C++ code,I wrote it: using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("user32.dll")] public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk); [DllImport("user32")] public static extern bool GetMessage(ref

PInvoke char* in C DLL handled as String in C#. Issue with null characters

两盒软妹~` 提交于 2019-11-28 03:10:39
问题 The function in C DLL looks like this: int my_Funct(char* input, char* output); I must call this from C# app. I do this in the following way: ...DllImport stuff... public static extern int my_Funct(string input, string output); The input string is perfectly transmitted to the DLL (I have visible proof of that). The output that the function fills out although is wrong. I have hexa data in it, like: 3F-D9-00-01 But unfortunately everything that is after the two zeros is cut, and only the first

P/Invoke dynamic DLL search path

…衆ロ難τιáo~ 提交于 2019-11-28 02:46:31
问题 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 other DLLs with same names so just renaming the first one won't help me) I must keep them in different directories. Hence my question: what options do I have to

How to dllimport in Microsoft Visual C++

跟風遠走 提交于 2019-11-28 01:08:09
问题 I have a DLL and I would like to use some of its functions. #include <iostream> using namespace std; extern "C" __declspec(dllimport) int Initialize(char* localPort, char* adminServerName, int rpcTimeout); int main() { int res = Initialize("7864", "6000@kabc", 10000); return 0; } I don't have the DLL's .lib file, so is there anyway I can link to it. One thing that comes to my mind is to use the LoadLibrary function and then use the GetProcAddress(). Is there any other way? When I compile the

EntryPointNotFoundException when binding C++ dll in C#

女生的网名这么多〃 提交于 2019-11-27 23:58:56
问题 I try to bind a simple c++ dll shown in http://msdn.microsoft.com/en-us/library/ms235636.aspx in my c# console app, but I get a EntryPointNotFoundException for Add within dll at runtime. My test class is namespace BindingCppDllExample { public class BindingDllClass { [DllImport("MathFuncsDll.dll")] public static extern double Add(double a, double b); } public class Program { public static void Main(string[] args) { double a = 2.3; double b = 3.8; double c = BindingDllClass.Add(a, b); Console

Need to activate a window

不羁岁月 提交于 2019-11-27 22:36:37
I have a situation like this. I have the window handle of an application. I need to activate it. I tried all these functions but is not working always.(most of the time , it doesn't work the first time and I'll have to manually click on it to activate it. Second attempt onwards it works fine) The reason why I am doing this is because I have code written in the Form.Activate event of the form which I need to execute. Application is a single instance application. When a new instance is created , it first checks for the existence of any other process, If found, the handle of old process is passed

Using pHash from .NET

旧城冷巷雨未停 提交于 2019-11-27 19:54:44
I am trying to use pHash from .NET First thing I tried was to register (regsvr32) phash.dll and asked here Second of all, i was trying to import using DllImport as shown below. [DllImport(@".\Com\pHash.dll")] public static extern int ph_dct_imagehash( [MarshalAs(UnmanagedType.LPStr)] string file, UInt64 hash); But when i try to access the method above during run-time, following error message shows up. Unable to find an entry point named 'ph_dct_imagehash' in DLL '.\Com\pHash.dll'. What does "entry point" means and why am I getting the error? Thank you. FYI - Here is the full source code using

PInvokeStackImbalance C# call to unmanaged C++ function

佐手、 提交于 2019-11-27 18:43:57
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 or mysterious bugs - yeah, I know that doesn't mean much. Here are the things that were checked: The dll name is correct. The entry point name is correct and has been verified with depends.exe - the code has to use the mangled name and it does. The calling

What is [DllImport(“QCall”)]?

浪子不回头ぞ 提交于 2019-11-27 18:15:33
Many methods in the .Net library are implemented in native code. Those that come from the framework itself are marked with [MethodImpl(MethodImplOptions.InternalCall)] . Those that come from some unmanaged DLL are marked with [DllImport] (e.g. [DllImport("kernel32.dll")] ). So far nothing unusual. But while writing answer for another question , I discovered there are many methods marked with [DllImport("QCall")] . They seem to be internal implementation of .Net (e.g. GC._Collect() ). My question is: What exactly does [DllImport("QCall")] mean? What is the difference between [DllImport("QCall")

How to use <DllImport> in VB.NET?

房东的猫 提交于 2019-11-27 17:14:45
问题 How should I DLLImport things in VB.NET? An example would be: <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer End Function If I put it inside a Class or somewhere else, I get "DLLimport is not defined" I am using Visual Studio 2008 Professional 回答1: You have to add Imports System.Runtime.InteropServices to the top of your source file.