Tag: dll

如何将函数从C ++ DLL正确导入到C#Project中

我可以使用如何正确地将C ++ DLL中的几个函数导入到我的C#应用​​程序中的帮助。 以下是C ++方面的一些示例,它们展示了我在C#中尝试做的事情。 我不认为我正确地编组了一些/或一些返回类型和一些参数(尤其是指针/ ref / out)。 C ++头文件声明: 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, float * pressure, unsigned short * chrono); C ++代码: /* Define functions prototype */ typedef unsigned long(__stdcall […]

用户代码未处理来自Dll get Exception的C#User Definedexception处理

我正在使用动态c#应用程序,它将所有类从我单独创建的Dll文件链接到主应用程序,在这些文件中,当我动态连接我的dll文件时,error handling程序希望通过连接抛出错误,因为它曾经是这是我尝试做的事情 我有一个dll文件,上面有这个编码和类 class clsGlobles { public object dlststus = false; // dtabase file status public clsGlobles() { try { if (dlststus == true) { } else { throw new Exception(“Some important files are missing – Please re-install the application”); //throw this as a error and stop running the program } } catch (Exception ex) […]

FileNotFoundException(找不到DLL)

我在客户端的一台机器上遇到了这个奇怪的错误。 它抛出FileNotFoundException,但是那个DLL肯定就在那个带有Executable的文件夹中..为什么它找不到它? 请指教..

从C ++ DLL调用C#函数

我有一个用C ++编写的DLL,我想将C#函数传递给C ++ DLL中的函数,并从C ++调用C#函数。 我该怎么办? 在此先感谢,请保持简单的答案。 我认为我不需要为此发布代码示例,但如果您需要,请询问。

通过p / invoke使用c#中的XGBoost DLL

我正在尝试使用XGBoost的 dll(libxgboost.dll)来创建一个DMatrix(就像一个2D数组)并获得它有多少列。 它运行正常,直到它在下面的代码中的int cols = …行抛出System.AccessViolationException : using System; using System.Runtime.InteropServices; namespace basicXgboost { class Program { [DllImport(“../../libs/libxgboost.dll”, CharSet = CharSet.Auto)] public static extern int XGDMatrixCreateFromFile([MarshalAs(UnmanagedType.LPStr)] string file, int silent, IntPtr outputPtr); [DllImport(“../../libs/libxgboost.dll”, CharSet = CharSet.Auto)] public static extern int XGDMatrixNumCol(IntPtr dmatrixPtr, IntPtr dmatrixColumnsPtr); static void Main(string[] args) { IntPtr dmatrixPtr = Marshal.AllocHGlobal(1000000); IntPtr dmatrixColumnsPtr […]

通过COM Interop公开C#类

我有一个C#类库,还有一个powerbuilder应用程序。 我想公开c#类并在powerbuilder应用程序中使用它。 我使用以下博客来公开这些function,以便powerbuilder应用程序访问它https://whoisburiedhere.wordpress.com/2011/07/12/creating-a-com-object-from-scratch-with-c/ http ://jumbloid.blogspot.com/2009/12/making-net-dll-com-visible.html 所以我暴露了COM并使其在powerbuilder中可访问,但我仍然有一些基本问题,以确保我遵循最佳指导方针。 该类在转换为COM之前看起来像 class classname { function1(){//do something} function2(){//do something} function3(){//do something} function4(){//do something} } 要转换为COM我创建了一个接口,我想只公开function1和function2。 所以我修改了类 [ComVisible(true)] [Guid(“03S3233DS-EBS2-5574-825F-EERSDG8999”),InterfaceType(ComInterfaceType.InterfaceIsDual)] interface Iinterface { function1(); function2(); } 在主类中,我做了以下修改1.我在AssemblyInfo中将COM可见属性设置为false,因为我不想公开所有公共方法。 2.class级看起来像 [ComVisible(true)] [Guid(“2FD1574DS4-3FEA-455e-EW60A-EC1DFS54542D”), ClassInterface(ClassInterfaceType.None)] class class1 : Iinterface { function1(){//do something} function2(){//do something} [ComVisible(false)] //i don’t want the mehtod to be exposed function3(){//do something} [ComVisible(false)] […]

由于导入C ++ DLL,C#ShowDialog()抛出错误

这个C#程序在没有使用showdialog()的情况下工作正常但是当我尝试使用showdialog()时它会产生“系统访问冲突”exception。 奇怪的!! C#代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace w_CSharp_GUI_1 { public partial class Form1 : Form { private String W_Addr,C_Addr,Pic_Addr=”lol”; [DllImport(“face_proj_trial_dll.dll”)] public static extern string f_detect(string path); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog2 […]

在C#中声明它从C ++ dll返回2点的函数?

我在C ++ DLL中有一个函数,它的返回值是2点,如下所示: #include “stdafx.h” #include using namespace std; double** _stdcall f(int *n) { vector t; vector X; int i=0, j=0; do { t.push_back(3*i-4); X.push_back(2*j); i++; j++; } while (i<15&&j<90); *n=i; double** ret = new double*[2]; for (i=0;i<2;i++) ret[i]=new double[*n]; for (i=0;i<*n;i++) { ret[0][i]=t[i]; ret[1][i]=X[i]; } return ret; } 现在,我在C#中声明这个函数如下: [DllImport(“exDP.dll”)] public static extern IntPtr[2] […]

C#:如何将DLL嵌入资源文件(程序目录中没有DLL复制)

我有一个需要X.dll的C#应用​​程序(项目A)。 我已将生成X.dll的项目添加到A作为Visual Studio中的参考。 我还将X.dll的发布版本添加到A中的资源文件中作为二进制文件。 我告诉项目A 不要将X.dll复制到输出目录。 现在我想要A.exe加载,说“嘿我找不到这个文件”,然后查看资源文件并使用Assembly.Load(byte [])获取X.dll。 我有代码重新魔术DLL,但这个代码永远不会被调用。 目前我有一个骨头简单的项目,只是试图让它工作。 它编译好了。 当我运行它时,我在X.dll上得到一个FileNotFoundException。 我有: [STAThread] static void Main() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); } 但* CurrentDomain_AssemblyResolve *中的断点永远不会被击中。 我立即得到一个FileNotFoundException。 当然有一些我遗失的东西?

是否可以将LPWSTR从C ++ DLL返回到C#app

C ++函数定义就是这样 __declspec(dllexport) LPWSTR __stdcall GetErrorString(int errCode); 我用C#这样称呼它 [DllImport(“DLLTest.dll”)] public static extern string GetErrorString(int errCode); static void Main(string[] args) { string result = GetErrorString(5); } 我得到System.Runtime.InteropServices.SEHException类型的未处理exception 我甚至不确定C ++ DLL是否可以尝试将LPWSTR返回给C#… 谢谢。