Thema: C# Zugriff auf Struct

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Zugriff auf Struct

  Alt 11. Apr 2015, 21:08
Hoffe jemand kann helfen.

Code:
  [Serializable, StructLayout(LayoutKind.Sequential)]
  public sealed class TAudioAttributes
  {
    public int Channels;
    public int SamplesPerSec;
    public int BitsPerSample;
    public double PlayTime;
    public UInt64  SampleCount;
    public int Bitrate;
  }
Code:
    //TagsLibrary_GetAudioAttributes
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("TagsLib.dll", EntryPoint = "TagsLibrary_GetAudioAttributes", CharSet = CharSet.Auto)]
    public static extern bool TagsLibrary_GetAudioAttributes(IntPtr HTags, TAudioType AudioType, IntPtr Attributes);
Aufruf in VB_NET

Code:
        Dim AudioAttributes As IntPtr

        If TagsLib.TagsLibrary_GetAudioAttributes(hTags, TAudioType.atAutomatic, AudioAttributes) Then
            txtChannels.Text = AudioAttributes.Channels.ToString
            txtSamplesPerSec.Text = AudioAttributes.SamplesPerSec.ToString
            txtBitsPerSample.Text = AudioAttributes.BitsPerSample.ToString
            txtPlayTime.Text = AudioAttributes.PlayTime.ToString
            txtSampleCount.Text = AudioAttributes.SampleCount.ToString
            txtBitRate.Text = AudioAttributes.Bitrate.ToString
        End If
AudioAttributes soll mir also einen pointer auf die TAudioAttributes struct zurück liefern.
Wie muss also die Rückgabe für die Struct geschrieben werden damit in VB_NET
ein zugriff auf

Code:
AudioAttributes.SamplesPerSec.ToString
erfolgen kann.

Für PWideChar musste ich auch so tricksen. (Was funktioniert)
Code:
    //TagsLibrary_GetTag
    public static string TagsLibrary_GetTag(IntPtr HTags, string Name, TTagType TagType)
    {
      IntPtr ptr = TagsLibrary_GetTagPtr(HTags, Name, TagType);
      if (ptr != IntPtr.Zero)
      {
        return Marshal.PtrToStringAuto(ptr);
      }
      return null;
    }
    [DllImport("TagsLib.dll", EntryPoint = "TagsLibrary_GetTag", CharSet = CharSet.Auto)]
    private static extern IntPtr TagsLibrary_GetTagPtr(IntPtr HTags, [In, MarshalAs(UnmanagedType.LPWStr)] string Name, TTagType TagType);



gruss
  Mit Zitat antworten Zitat