dllimport

Unhandled Exception: System.AccessViolationException: Attempted to read or write

旧时模样 提交于 2019-12-08 05:12:55
问题 Below is my c++ DLL // DLL.cpp : Defines the exported functions for the DLL application. #include "stdafx.h" //#include <stdexcept> #include<iostream> using namespace std; typedef void (*FunctionPtr)(int); void (*FunctionPtr1)(int); extern "C" __declspec(dllexport)void Caller(); extern "C" __declspec(dllexport)void RegisterFunction(FunctionPtr func_ptr); extern void Caller() { int i = 10; FunctionPtr1(i); } extern void RegisterFunction(FunctionPtr func_ptr1) { FunctionPtr1 = func_ptr1; } This

PInvoke code usage in C#

倾然丶 夕夏残阳落幕 提交于 2019-12-08 02:41:17
问题 I have the following C# code that uses DLLImport. using System; namespace LvFpga { class RegTest { [DllImport("kernel32")] public extern static int LoadLibrary(string lpLibFileName); [DllImport("kernel32")] public extern static bool FreeLibrary(int hLibModule); public static bool IsDllRegistered(string DllName) { int libId = LoadLibrary(DllName); if (libId>0) FreeLibrary(libId); return (libId>0); } public static void Main(string[] args) { Console.WriteLn(IsDllRegistered("msdia100.dll")); } }

Using Unicode strings in DllImport with a DLL written in Rust

那年仲夏 提交于 2019-12-07 20:40:16
问题 I am trying to call a DLL written in Rust from a C# program. The DLL has two simple functions that take stings (in different manner) and prints to the console. Rust DLL code #![crate_type = "lib"] extern crate libc; use libc::{c_char}; use std::ffi::CStr; #[no_mangle] pub extern fn printc(s: *const c_char){ let c_str : &CStr = unsafe { assert!(!s.is_null()); CStr::from_ptr(s) }; println!("{:?}", c_str.to_bytes().len()); //prints "1" if unicode let r_str = std::str::from_utf8(c_str.to_bytes())

Calling unmanaged c++ code in C# Mixed with STL

时光怂恿深爱的人放手 提交于 2019-12-07 19:39:36
问题 Hey, I want to call unmanaged c++ code in C# The function interface is like following(I simplified it to make it easy to understand) Face genMesh(int param1, int param2); Face is a struct defined as: struct Face{ vector<float> nodes; vector<int> indexs; } I googled and read the MSDN docs found ways to call simple c/c++ unmanged code in C#, also know how to hand the struct as return value. And My question is how to handle "vector". I did not find rules about mapping between vector and some

Frame Capture using Matrox Commands

穿精又带淫゛_ 提交于 2019-12-07 15:48:43
问题 I'm working on a project where I have to set the fps of a video stream (as 10) from a camera and grab a frame every 5th frame. I'm working on a program that has already been half written by someone else. The thing is, they have used Matrox Framegrabber dlls. There is also Matrox Frame Grabber on the device. But I cant find any commands for framegrab in C#. I found the following code for C++. MIL_ID MdispAlloc(SystemId, DispNum, DispFormat, InitFlag, DisplayIdPtr) where MIL_ID SystemId; System

Using DLLImport to import a class

倖福魔咒の 提交于 2019-12-07 15:31:08
问题 I have an class in dll: For example: namespace foo { public class baa { /* ... */ } } how can I imports the baa class from dll? it is possible? [DllImport(DllName)] public extern ?? foo() ?? Thanks in advance. 回答1: That's not going to work. Unmanaged DLLs export a C interface, not a C++ one. And for managed DLLs (C# or C++/CLI) you simply don't need DllImport. Only functions that are imported into a static class I'm afraid. 回答2: DllImport is used only when you want to invoke unmanaged

How dynamic linking reacts on a change in object

情到浓时终转凉″ 提交于 2019-12-07 11:14:37
问题 I have compiled a component (say X.exe ) linked with a dynamic library (say Y.dll ). X and Y have been released. Now I have made a small change in an object's function which Y holds: I've delete d a leaked object and made its pointer NULL . To apply this change with full compatibility what should I do? Need to recompile component X with the new library file and need to replace the DLL as well; Recompiling X with new library file would be enough; Replacing the DLL would be enough. 回答1: Now I

Load C library (gsdll32.dll) from Metro Style App c#

余生颓废 提交于 2019-12-07 10:15:38
问题 I want to use gsdll32.dll from Metro Style App c#. I load dll as follow: [DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")] private static extern void gsapi_delete_instance(IntPtr instance); [DllImport("gsdll32.dll", EntryPoint = "gsapi_revision")] private static extern int gsapi_revision(ref GS_Revision pGSRevisionInfo, int intLen); [DllImport("gsdll32.dll", EntryPoint = "gsapi_set_stdio")] private static extern int gsapi_set_stdio(IntPtr lngGSInstance, StdioCallBack gsdll

C# Marshalling char** and unsigned char**

一曲冷凌霜 提交于 2019-12-07 09:11:42
问题 Here is the problem - i have some C image processing library that i need to use from C# application. Lack of experience with DllImport strikes me hard for now. The function i need to use looks like: IMAGEPROCESS_API const int importImage ( const unsigned char* image, const char* xmlInput, unsigned char** resultImage, char** xmlOutput ); So, it accepts raw image data, xml containing parameters and image width'height and then return processed image and some xml report. For now im trying to

Importing a DLL in C#

我只是一个虾纸丫 提交于 2019-12-07 07:57:19
问题 I'm trying to import a dll to my C# project using DllImport as follows: [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key,string val,string filePath); Also, I have added the namespace System.Runtime.InteropServices: using System.Runtime.InteropServices; Still, I'm getting an error: "The name 'DllImport' does not exist in the current context" Is there a limitation on where in a class you can import a dll? 回答1: You've probably also got the