AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein C# Record/Struct rückgabe by ref/var
Thema durchsuchen
Ansicht
Themen-Optionen

Record/Struct rückgabe by ref/var

Ein Thema von EWeiss · begonnen am 22. Mai 2015 · letzter Beitrag vom 23. Mai 2015
 
EWeiss
(Gast)

n/a Beiträge
 
#1

Record/Struct rückgabe by ref/var

  Alt 22. Mai 2015, 03:06
Delphi
Delphi-Quellcode:
  PBASSVIS_PARAM = ^TBASSVIS_PARAM;
  TBASSVIS_PARAM = record
    VisHandle : HVIS;
    VisGenWinHandle : DWORD;
    Kind : TBASSVIS_KIND_T;
  end;
C#
Code:
    [Serializable, StructLayout(LayoutKind.Sequential)]
    public sealed class BASSVIS_PARAM
    {
        public int VisHandle;
        public IntPtr VisGenWinHandle;
        public BASSVISKind Kind;
        public BASSVIS_PARAM(BASSVISKind kind)
        {
            this.Kind = kind;
            this.VisHandle = 0;
            this.VisGenWinHandle = IntPtr.Zero;
        }

        public BASSVIS_PARAM(BASSVISKind kind, int visHandle)
        {
            this.Kind = kind;
            this.VisHandle = visHandle;
            this.VisGenWinHandle = IntPtr.Zero;
        }
    }
Die procedure
Delphi

Delphi-Quellcode:
procedure BASSVIS_Free(
    var Base: TBASSVIS_PARAM
); stdcall; external dllfile;
C#
Code:
       
//BASSVIS_Free
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("bass_vis.dll", EntryPoint = "BASSVIS_Free", CharSet = CharSet.Auto)]
public static extern void BASSVIS_Free(BASSVIS_PARAM param);

Meine Frage ist wie kann ich in C# by ref die Classe zurückgeben?

In Delphi funktioniert das soweit alles.
procedure BASSVIS_Free(var Base: TBASSVIS_PARAM); stdcall;

Wurde das Plugin freigegeben dann setze ich die Handles auf 0.
Delphi-Quellcode:
Base.VisHandle := 0;
Base.VisGenWinHandle := 0;
Wie kann ich das jetzt in C# umsetzen?
Ein einfaches
Code:
public static extern void BASSVIS_Free(ref BASSVIS_PARAM param);
Sollte eigentlich funktionieren aber bei der Umsetzung in der Anwendung gibt es Probleme.
Das würde theoretisch funktionieren.. (Zumindest wird kein Fehler angezeigt)
Code:
BassVis.BASSVIS_Free(ref_visParam);
bool bFree = _visParam.VisHandle == 0;
if (!bFree)
Das hingegen nicht..
Code:
private IVisualization Viz = null;
//...............
BassVis.BASSVIS_Free(ref Viz.VizParam);
bool bFree = Viz.VizParam.VisHandle == 0;
if (bFree)
Error:
Zitat:
Error 15 A property, indexer or dynamic member access may not be passed as an out or ref Parameter
IVisualization ist so ausgelegt..
Code:
public interface IVisualization
{
  BassVis_Api.BASSVIS_PARAM VizParam { get; }
Nur hier kann ich kein "ref" übergeben.

gruss

Geändert von EWeiss (22. Mai 2015 um 03:14 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:23 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