Thank you very much !! I got it :))
Willow2008
Posts
-
function call from an c++ dll in c# -
function call from an c++ dll in c#Sorry to bother you :(( I´m very glad about your help !! And I have to excuse me but I don´t have much experience in C# coding..:( I will give you more details what I want to do: I have a windows programm from and I have to make a communication to this programm. The supplier of the other programm provided me a dll with different functions inside. Now from my understanding the easiest way to setup the communication is to use this dll. So I only wanted to make a short trial if I can call this functions and if the communication can be established ! Fct1, Fct3 and Fct4 are returning a value that shows a good result. The problem is Fct2 where I have to deal with pointer :((( Thanks again !!
-
function call from an c++ dll in c#using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Data;namespace ConsoleApplication1
{
class Program
{
[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)]
extern static int Fct1();\[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)\] extern static int Fct2(); \[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)\] extern static int Fct3(IntPtr Size, byte\[\] data, int timeout); \[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)\] extern static int Fct4(int size, byte\[\] data); static void Main(string\[\] args) { byte\[\] data = new byte\[5\] {0x01,0x02,0x03,0x04,0x05}; int result = Fct1(); Console.WriteLine(result); result = Fct2((IntPtr)2, data, 3); Console.WriteLine(result); result = Fct3(3, data); Console.WriteLine(result); result = Fct4(); Console.WriteLine(result); } }
}
ErrorMessage: AccessViolation at Fct2
-
function call from an c++ dll in c#Hello, I hope somebody can help me and I hope I put my questions into the right forum !! If not pls let me know !! I received a c++ dll with a function inside: int FunctionCall(int* Size, unsigned char Data[], int time) I used the DLLImport:
[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)]
extern static int FunctionCall(IntPtr Size, byte[] data, int timeout);But when I debug I always get an out of range error !! What did I wrong ?? Thank you very much for your help !!