dllimport

How to call a C++ function with a struct pointer parameter from C#?

前提是你 提交于 2019-12-10 02:31:25
问题 Okay one more function that it's not yet working. I am basically calling some C++ functions from C# by using P/Invoke. The problematic function does query a show laser device for some device related information, such as minimal and maximal scan rates and maximal points per second. The problematic function is: int GetDeviceInfo(DWORD deviceIndex, DeviceInfo* pDeviceInfo); Here's the C++ header file that I was given. That's a link to the very brief C++ SDK description. I don't have the sources

C++ from C#: C++ function (in a DLL) returning false, but C# thinks it's true!

青春壹個敷衍的年華 提交于 2019-12-10 01:35:01
问题 I'm writing a little C# app that calls a few functions in a C++ API. I have the C++ code building into a DLL, and the C# code calls the API using DllImport. (I am using a .DEF file for the C++ DLL so I don't need extern "C".) So far the API has one function, which currently does absolutely nothing: bool Foo() { return false; } In C#, I have the following: public class FooAPI { [DllImport("Foo.dll")] public static extern bool Foo(); } ... bool b = FooAPI.Foo(); if (!b) { // Throw an exception

__cdecl and __declspec calling conventions confusion

送分小仙女□ 提交于 2019-12-09 17:29:47
问题 I am writing a DLL for a third party application. The main software engineer mentions that the application uses the __cdecl (/Gd) calling convention. That I need to make sure that I use that. Additionally, the third party has provided to me a C++ DLL skeleton which exports the functions as follows: #ifdef _EXPORTING #define DECLSPEC __declspec(dllexport) #else #define DECLSPEC __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif DECLSPEC int ICD_Create(char* id); .... .... I am

How to P/Invoke when pointers are involved

不问归期 提交于 2019-12-09 16:19:53
问题 In an attempt to learn to use PInvoke in C#, I'm a little unsure how to handle various cases with pointers involving simple value types. I'm importing the following two functions from an unmanaged DLL: public int USB4_Initialize(short* device); public int USB4_GetCount(short device, short encoder, unsigned long* value); The first function uses the pointer as an input, the second as an output. Their usage is fairly simple in C++: // Pointer as an input short device = 0; // Always using device

Asp.Net C# DllImport problem

六月ゝ 毕业季﹏ 提交于 2019-12-08 19:44:14
问题 I want to import DLL file in my web site project. I have dll file "my.dll" in folder C:\DLLDir and I'm using the code : [DllImport("C:\\DLLDir\\my.dll", EntryPoint = "Out32")] This works ok. But I want to use relative path (web site root path) . I'm trying to put "my.dll" in "bin" or root folder and I'm using the code : [DllImport("my.dll", EntryPoint = "Out32")] but I'm getting the error: Unable to load DLL 'my.dll': The specified module could not be found. (Exception from HRESULT:

dllimport failed to locate dll even though it is in the PATH

泪湿孤枕 提交于 2019-12-08 17:43:40
问题 I use [Dllimport("DllName.dll")] where I'm sure a path to my dll exists in the process PATH environment variable, and still I get "DllName.dll could not be found" 回答1: "DllName.dll could not be found" could also mean that DllImport has not found one of DllName.dll dependencies. Grab Dependecy Walker to check which dependecy you are missing. 回答2: I'd suggest you to use FileMon (sysinternals.com) to check if your assumptions about the library location are right. 回答3: DllImport does not consult

C# Marshalling unsigned char* array from C++ DLL (in and out)

房东的猫 提交于 2019-12-08 14:07:13
问题 I am having trouble marshalling data between a C# application and an existing C++ DLL. The caveats that are making this difficult are that it is an unsigned char pointer to an array, and I need access to the data (from all fields) after the call in C#. I would like to avoid using unsafe code, if at all possible. Here is the C++ signature: BYTE GetData(unsigned char *Data_Type, unsigned char *Data_Content, unsigned int *Data_Length); I've tried a bunch of things in C#, but here's what I have

how to use loaded DLLS assembly' methods which is referenced to another assembly?

我的未来我决定 提交于 2019-12-08 09:12:22
i have 2 assemblies. i added classlib1 into classLib2 references. like that: and i used it like that: namespace ClassLibrary2 { public class Class1 { public Class1() { } public int GetSum(int a , int b) { try { ClassLibrary1.Class1 ctx = new ClassLibrary1.Class1(); return ctx.Sum(a, b); } catch { return -1; } } } } Also i want to load (class1lib and Class2Lib) another C# project dynamically by using AppDomain. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Reflection; using

how to use loaded DLLS assembly' methods which is referenced to another assembly?

我的梦境 提交于 2019-12-08 08:07:37
问题 i have 2 assemblies. i added classlib1 into classLib2 references. like that: and i used it like that: namespace ClassLibrary2 { public class Class1 { public Class1() { } public int GetSum(int a , int b) { try { ClassLibrary1.Class1 ctx = new ClassLibrary1.Class1(); return ctx.Sum(a, b); } catch { return -1; } } } } Also i want to load (class1lib and Class2Lib) another C# project dynamically by using AppDomain. using System; using System.Collections.Generic; using System.Linq; using System.Web

dynamically running a DLL at a remote Windows box?

时光怂恿深爱的人放手 提交于 2019-12-08 06:17:09
问题 Is there a way of dynamically running a DLL at a remote Windows box? Say a user wants to send a his own DLL file to a remote server and run a function in that DLL at the remote site. The user may be able to provide function entry points as well as required parameters, but no more. (e.g. no header file) I am thinking of setting up an agent executable at the remote site that can (1) dynamically load and bind a unknown DLL and (2) run a function with parameters. Is this a good a approach, or is