Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   .NET-Sprachen (https://www.delphipraxis.net/82-net-sprachen/)
-   -   C# C++ dll array einlesen ? (https://www.delphipraxis.net/178479-c-c-dll-array-einlesen.html)

madina 10. Jan 2014 08:18

C# C++ dll array einlesen ?
 
Hallo,

ich habe ein dll (Borland C++), wo er ein 2D Array Daten liefert:
1.extern "C" MP5 Berechne(int iM, int iJ);

struct MP5
{
int iTMJ[5][12];
};

MP5 iTMJ;

MP5 _export Berechne(int iM, int iJ)
{
ArrayFüllung...
return(iTMJ);
}

2.C#:
public struct MP5 { public static int[,] iFelder = new int[5, 12];}

MP5 iTMJ;

[DllImport("my.dll", EntryPoint = "Berechne", CallingConvention = System.Runtime.InteropServices.CallingConvention.C decl, CharSet = CharSet.Auto, SetLastError = true)]
public static extern MP5 Berechne(int iM, int iJ);

Am Ende rufe ich die im DLL enthaltene Funktion auf und übergebe auch Daten:

iTMJ = Berechne(12, 2013);

Bei der letzten Zeile, wo ich die Funktion aufgerufen wird, stürzt er ab und die 2D Daten werden nicht dem iTMJ zugewiesen warum ?

MFG

Furtbichler 12. Jan 2014 13:16

AW: C# C++ dll array einlesen ?
 
So könnte es gehen (Rückgabetype 'IntPtr' ):
Code:
[DllImport(...)]
public static extern IntPtr Berechne(int iM, int iJ);

...
 IntPtr ptr = Berechne(12, 2013);
 MP5 mp5 = (MP5)Marshal.PtrToStructure(ptr, typeof(MP5));

madina 15. Jan 2014 07:58

AW: C# C++ dll array einlesen ?
 
Hallo,

leider führt zu keinem Datenempfang.

MFG

Furtbichler 15. Jan 2014 11:36

AW: C# C++ dll array einlesen ?
 
Probiere mal, die Adresse zu übergeben:
Code:
*MP5 _export Berechne(int iM, int iJ)
 {
 ArrayFüllung...
 return(@iTMJ);
 }

madina 16. Jan 2014 12:06

AW: C# C++ dll array einlesen ?
 
Hallo,

sollte diese Änderung in der my.dll passieren ?

MFG


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz