dllimport

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

你离开我真会死。 提交于 2019-12-20 03:03:25
问题 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

Unresolved external symbol _declspec(dllimport)

╄→гoц情女王★ 提交于 2019-12-20 02:38:51
问题 I've created an DLL for my Console Application in Visual Studio. In my DLL I have a Class named Dialog_MainMenu with has a *.cpp file and a *.h file. Following error message : Error 9 error LNK2001: unresolved external symbol "__declspec(dllimport) public: static enum Dialog_MainMenu::GAME_STATES Dialog_MainMenu::CurrentGameState" (_ imp ?CurrentGameState@Dialog_MainMenu@@2W4GAME_STATES@1@A) C:\Users\Kevin\Desktop\c++ projects\development_testing\The Intense Adventure\Dialogs\Dialog_MainMenu

Passing StringBuilder to DLL function expecting char pointer

独自空忆成欢 提交于 2019-12-20 01:58:05
问题 I'm trying to interact with a DLL library created in Delphi. In C++, I made this call perfectly fine: for(int y = 1; y <= 12; y++) { char * chanName = (char *) malloc(21); memset(chanName,0,21); channelName(y,20,chanName); ... } Where channelName is type defined as typedef int (CALLBACK* ChannelName)(int,int,char*); Now I'm trying to do the same thing in C#. I've searched and found that StringBuilder is commonly used as a char pointer for DLL functions. Here is how I declared my function:

definition of dllimport function not allowed

♀尐吖头ヾ 提交于 2019-12-19 22:02:15
问题 While compiling a C code, I'm getting the following error: c:\users\kbarman\documents\mser\vlfeat-0.9.13-try\mser\stringop.c(71): error C2491: 'vl_string_parse_protocol' : definition of dllimport function not allowed In the file stringop.c, I have the following function: VL_EXPORT char * vl_string_parse_protocol (char const *string, int *protocol) { char const * cpt ; int dummy ; /* handle the case prot = 0 */ if (protocol == 0) protocol = &dummy ; /* look for :// */ cpt = strstr(string, "://

DllImport or LoadLibrary for best performance

戏子无情 提交于 2019-12-18 16:49:09
问题 I have external .DLL file with fast assembler code inside. What is the best way to call functions in this .DLL file to get best performance? 回答1: Your DLL might be in python or c++, whatever , do the same as follow. This is your DLL file in C++. header: extern "C" __declspec(dllexport) int MultiplyByTen(int numberToMultiply); Source code file #include "DynamicDLLToCall.h" int MultiplyByTen(int numberToMultiply) { int returnValue = numberToMultiply * 10; return returnValue; } Take a look at

Generate C# DLLImport declarations from a native dll

五迷三道 提交于 2019-12-18 14:12:52
问题 Do you know a soft which automatically generates C# code (with [DllImport] attributes in .cs) from a native DLL in order to use this DLL in a C# code? 回答1: Checkout the P/Invoke Interop Assistant: In marshalling, there are a bunch of attributes and rules. Understanding all those attributes and rules seem a bit daunting. In order to make developing work more efficient and easier on those attributes and the rules, P/Invoke Interop Assistant comes out. It is a toolkit that helps developers to

How to import const char* API to C#?

廉价感情. 提交于 2019-12-18 13:25:50
问题 Given this C API declaration how would it be imported to C#? const char* _stdcall z4LLkGetKeySTD(void); I've been able to get this far: [DllImport("zip4_w32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "z4LLkGetKeySTD", ExactSpelling = false)] private extern static const char* z4LLkGetKeySTD(); 回答1: Try this [DllImport("zip4_w32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "z4LLkGetKeySTD", ExactSpelling = false)] private extern static IntPtr

How do I import and call unmanaged C dll with ANSI C string “char *” pointer string from VB.NET?

不打扰是莪最后的温柔 提交于 2019-12-18 09:08:48
问题 I have written my own function, which in C would be declared like this, using standard Win32 calling conventions: int Thing( char * command, char * buffer, int * BufSize); I have the following amount of Visual Basic code figured out, which should import the DLL file and call this function, wrapping it up to make it easy to call Thing("CommandHere",GetDataBackHere). UPDATE: This code is now a working solution, as shown here: Imports Microsoft.VisualBasic Imports System.Runtime.InteropServices

Getting distorted images after sending them from C# to OpenCV in C++?

烂漫一生 提交于 2019-12-18 08:49:19
问题 I created a C DLL out of my C++ class which uses OpenCV for image manipulations and want to use this DLL in my C# application. Currently, this is how I have implemented it: #ifdef CDLL2_EXPORTS #define CDLL2_API __declspec(dllexport) #else #define CDLL2_API __declspec(dllimport) #endif #include "../classification.h" extern "C" { CDLL2_API void Classify_image(unsigned char* img_pointer, unsigned int height, unsigned int width, char* out_result, int* length_of_out_result, int top_n_results = 2)

Using 32-bit dll on 64-bit system shows 0x8007000B Error

北城余情 提交于 2019-12-18 07:46:40
问题 I have to use a third party DLL in my application. The DLL is a 32-bit and the system I am using is 64-bit OS. I have Imported the 32-bit DLL in my DotNet application (framework-4.5) as below [DllImport("Sample.dll", EntryPoint = "Add", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern int Add(int iA, int iB); In IIS 7.5 - I have set "Enable 32-bit Application" as "True". And also tried setting the Compiler Manager as - X86, x64 and Any CPU. But all