struct in managed code verwenden
-
Hallo zusammen,
ich habe ein C++/CLI Projekt und möchte gerne eine Struktur aus einem C++ Projekt in meinem nutzen. Das C++ projekt stellt eine DLL und LIB bereit, die ich in meinem Projekt importiert habe. Ich kann auch die entsprechenden Methoden aufrufen. Nun möchte ich eine Funktion aufrufen, die als parameter eine im C++ Projekt definierte struktur erwartet..
hier der Code:
... typedef struct { int Revision; // For Image Capture int Resolution; int BinMode; int XStart; int YStart; int GreenGain; int BlueGain; int RedGain; int MaxExposureTimeIndex; int ExposureTime; // For Image Rendor bool ImageRendorFitWindow; int Gamma; int Contrast; int Bright; int SharpLevel; bool BWMode; bool HorizontalMirror; bool VerticalFlip; // For Capture Files. int CatchFrames; bool IsAverageFrame; bool IsCatchRAW; bool IsRawGraph; bool IsCatchJPEG; bool CatchIgnoreSkip; } TImageControl; typedef TImageControl *PImageCtl; ...
Die Funktion, die ich aufrufen möchte lautet:
MTUSB_SetFrameSetting( DEV_HANDLE DevHandle, PImageCtl SettingPtr);
und nimmt als Parameter PImageCtl!
Ich habe nun versucht, diese Struktur über marshalling in meinem Projekt verwendbar zu machen, doch es scheitert allein schon daran, dass ich den Befehl "[StructLayout(LayoutKind.Explicit)]" nicht nutzen kann. Hier der Versuch, den ich unternommen hatte:
[StructLayout(LayoutKind.Explicit)] public struct ImageControl { //For Image Capture (this is the TImageControl struct in the Mightex lib) [XmlElement("Revision")] [FieldOffset(0)] public int _revision; //Reserved for internal use only [FieldOffset(4)] public int _resolution; //indices: 0=32x32, 1=64x64, 2=160x120, 3=320x240, 4=640x480, 5=800x600, 6=1024x768, 7=1280x1024 [FieldOffset(8)] public int _binMode; //1 ?No Skip mode, 2 ?2X skip(1:2 decimation) [FieldOffset(12)] public int _xStart; //Upper left hand corner, positive right [FieldOffset(16)] public int _yStart; //Upper left hand corner, positive down [FieldOffset(20)] public int _greenGain; //Green Gain Value: 0 ?128, the actual gain is GreenGain/8 [FieldOffset(24)] public int _blueGain; //Blue Gain Value: 0 ?128, the actual gain is BlueGain/8 [FieldOffset(28)] public int _redGain; //Red Gain Value: 0 ?128, the actual gain is RedGain/8 [FieldOffset(32)] public int _maxExposureTimeIndex; //Maximum exposure time index: 0=5ms, 1=10ms, 2=100ms, 3=750ms [FieldOffset(36)] public int _exposureTime; //current exposure time in microseconds //For Image Render //bool is one byte // JTZ: for STDCALL version, the struct layout is different from the CDECL version. /* [FieldOffset(40)] public bool _imageRendorFitWindow; //True if the image always fit video window, otherwise False [FieldOffset(41)] public int _gamma; //Gamma value: 0 ?20, means 0.0 ?2.0 [FieldOffset(45)] public int _contrast; //Contrast value: 0 ?100, means 0% -- 100% [FieldOffset(49)] public int _bright; //Brightness : 0 ?100, means 0% -- 100% [FieldOffset(53)] public int _sharpLevel; //SharpLevel index: 0=Normal, 1=Sharp, 2=Sharper, 3=Sharpest [FieldOffset(57)] public bool _blkWhtMode; //true for B&W [FieldOffset(58)] public bool _horzMirror; //true for Horiz [FieldOffset(59)] public bool _vertFlip; //true for vertical flip //For Capturing files [FieldOffset(60)] public int _catchFrames; //Number of frames to be captured [FieldOffset(64)] public bool _isAvgFrame; //Save only one frame, but it’s the average of all grabbed frames [FieldOffset(65)] public bool _isCatchRaw; //Save as RAW Data File? [FieldOffset(66)] public bool _isRawGraph; //Save as JPG or BMP, but not corrected by Gamma, contrast, bright and sharp algorithm [FieldOffset(67)] public bool _isCatchJPEG; //Save as JPEG [FieldOffset(68)] public bool _catchIgnoreSkip; //always capture full resolution (but may display with decimation */ [FieldOffset(40)] public bool _imageRendorFitWindow; //True if the image always fit video window, otherwise False [FieldOffset(44)] public int _gamma; //Gamma value: 0 ?20, means 0.0 ?2.0 [FieldOffset(48)] public int _contrast; //Contrast value: 0 ?100, means 0% -- 100% [FieldOffset(52)] public int _bright; //Brightness : 0 ?100, means 0% -- 100% [FieldOffset(56)] public int _sharpLevel; //SharpLevel index: 0=Normal, 1=Sharp, 2=Sharper, 3=Sharpest [FieldOffset(60)] public bool _blkWhtMode; //true for B&W [FieldOffset(61)] public bool _horzMirror; //true for Horiz [FieldOffset(62)] public bool _vertFlip; //true for vertical flip //For Capturing files [FieldOffset(64)] public int _catchFrames; //Number of frames to be captured [FieldOffset(68)] public bool _isAvgFrame; //Save only one frame, but it’s the average of all grabbed frames [FieldOffset(69)] public bool _isCatchRaw; //Save as RAW Data File? [FieldOffset(70)] public bool _isRawGraph; //Save as JPG or BMP, but not corrected by Gamma, contrast, bright and sharp algorithm [FieldOffset(71)] public bool _isCatchJPEG; //Save as JPEG [FieldOffset(72)] public bool _catchIgnoreSkip; //always capture full resolution (but may display with decimation }
Es werden dann folgende Fehlermeldungen ausgegeben:
error C2144: Syntaxfehler: 'System::Runtime::InteropServices::LayoutKind' sollte auf ')' folgen
error C2144: Syntaxfehler: 'System::Runtime::InteropServices::LayoutKind' sollte auf ']' folgen
error C2512: 'System::Runtime::InteropServices::StructLayoutAttribute::StructLayoutAttribute': Kein geeigneter Standardkonstruktor verfügbar
error C2143: Syntaxfehler: Es fehlt ';' vor '.'
error C2059: Syntaxfehler: '.'
error C2059: Syntaxfehler: ')'
error C2143: Syntaxfehler: Es fehlt ';' vor '{'
error C2447: '{': Funktionsheader fehlt - Parameterliste im alten Stil?generell die frage... wie kann ich nun in meinem .Net-projekt ein Objekt der Struktur "TImageControl" anlegen, dieses mit Werte befüllen und der Funktion "MTUSB_SetFrameSetting( DEV_HANDLE DevHandle, PImageCtl SettingPtr);" übergeben?
VIELEN DANK für eure Hilfe... komme nämlich hier gerade nicht weiter!!
Gruß
-
Hallo,
ersetze "." mit "::":
[StructLayout(LayoutKind::Explicit)]
MfG,
Probe-Nutzer