dllimport

Compile error for (char based) STL (stream) containers in Visual Studio

半腔热情 提交于 2019-12-02 14:29:43
问题 This is basically the same question as [SO]: C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed [closed], but considering the following facts: That (on my opinion) is a perfectly valid question (according to [SO]: How to create a Minimal, Complete, and Verifiable example), I really don't know why some users felt the urge of closing it The answer marked as a solution provides guidelines the for fixing the error (in general), but doesn't apply to current

How do I properly import functions from a C++ DLL into my C# Project

我的梦境 提交于 2019-12-02 13:04:53
I could use help with how to properly import several functions from a C++ DLL into my C# application. Here are a couple examples from the C++ side that show what I am trying to do in C#. I do not think I am properly marshaling either/or some of the return types and some of the parameters (especially pointers/ref/out). C++ Header File Declarations: unsigned long __stdcall mfcsez_initialisation(unsigned short serial); unsigned char __stdcall mfcs_get_serial(unsigned long int handle, unsigned short * serial); unsigned char __stdcall mfcs_read_chan(unsigned long int handle, unsigned char canal,

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

微笑、不失礼 提交于 2019-12-02 13:01:19
问题 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.

How can I write a signature on C# for a wrapped C++ method having a pointer to a function it its arguments?

送分小仙女□ 提交于 2019-12-02 12:56:27
问题 I'm writing a wrapper for a dll. The dll has a method whose signature resembles the following: unsigned long aMethod(void *anyParameter, void (*anotherMethod)(const char *, void *)) I've searching at google for a tutorial to give me insight on how to write the signature on C# so the framework can do the marshalling process. How can it be written? Do you know about any tutorial, book or documentation on this subject? 回答1: [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void

Compile error for (char based) STL (stream) containers in Visual Studio

◇◆丶佛笑我妖孽 提交于 2019-12-02 10:43:01
This is basically the same question as [SO]: C2491: 'std::numpunct<_Elem>::id' : definition of dllimport static data member not allowed [closed] , but considering the following facts: That (on my opinion) is a perfectly valid question (according to [SO]: How to create a Minimal, Complete, and Verifiable example ), I really don't know why some users felt the urge of closing it The answer marked as a solution provides guidelines the for fixing the error (in general), but doesn't apply to current case, and certainly, doesn't fix it , please don't close it or mark it as a duplicate (at least, not

Marshalling string from c# to c++

我的梦境 提交于 2019-12-02 09:59:30
I am new in microsoft world. I have lot of problem trying to pass a simple string from c# to dll/c++ I have read a lot of post and documentation about but the problem is the same. C++ code extern "C" __declspec(dllexport) int Init( long l , char* url ); C# code [DllImport("MCRenderer.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = false)] public static extern int Init(long a, StringBuilder url); Init(hndl.ToInt64(), str ); what haeppen is that long value is passed correctly while string parameter is 0x00000000 <Bad Ptr> can you help me ... Iam really confused thanks!! AG You

Unable to find type or namespace of imported DLL

我与影子孤独终老i 提交于 2019-12-02 09:34:38
I downloaded the "smilenet-1.2.1-win64-academic" library from this page and imported the smileNET.dll in my Unity project. Then I restarted my visual studio, and when I tried to use the library, it gave me an error that the type or namespace could not be found. I tried using Smile; and using smileNET; as indicated in their documentation file Hello.cs but it did not work. I tried 64 bit version as well as 32 bit one. My unity version is 2018.1.8f1 64bit When I inspected the downloaded dll, it said that the >NET version is v4.0.30319 while my VS2017 is running version 4.7.03056 , could that be a

How can I write a signature on C# for a wrapped C++ method having a pointer to a function it its arguments?

强颜欢笑 提交于 2019-12-02 08:03:56
I'm writing a wrapper for a dll. The dll has a method whose signature resembles the following: unsigned long aMethod(void *anyParameter, void (*anotherMethod)(const char *, void *)) I've searching at google for a tutorial to give me insight on how to write the signature on C# so the framework can do the marshalling process. How can it be written? Do you know about any tutorial, book or documentation on this subject? [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void AnotherMethodDelegate(string s, IntPtr anyParameter); [DllImport("dllname", CallingConvention = CallingConvention

Finding the class name of the On-Screen Keyboard?

时光毁灭记忆、已成空白 提交于 2019-12-02 07:20:15
问题 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

P/Invoking to Native DLL with Runtime Filename

我是研究僧i 提交于 2019-12-02 06:51:08
问题 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