Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Records von Delphi in VB6 verwenden

  Alt 22. Feb 2015, 17:34
Vorab es kann was länger werden.

Vergleich von Records und Types in VB
VB!
Alignment bedeutet dass die Variablen an einem Raster einer bestimmten Anzahl Bytes ausgerichtet werden.
Packed Record bedeutet dass ein Alignment von 1 verwendet wird, was soviel bedeutet wie dass kein Alignemnt verwendet werden soll.
z.B. bei einem Alignment von 4 (ist in VB üblich) werden die Variablen an einem Raster von 4 Bytes ausgerichtet.

zur Verdeutlichung ein kleines Beispiel:
Code:
Private Type TA1
    v1 As Integer ' 2 
    v2 As Integer ' 2
    v3 As Long    ' 4
End Type          

Private Type TA2
    v1 As Byte ' 1
    v2 As Long ' 4
End Type      

Private Sub Form_Load()
    Dim t1 As TA1
    MsgBox LenB(t1) '8 wie zu erwarten
   
    Dim t2 As TA1
    MsgBox LenB(t2) ' auch 8 !
   
End Sub
Habe dem Programmiere der DLL mitgeteilt das er die Records auf Packet umstellen soll.
Soweit so gut!
Nun mein Problem.
Trotz Packet kommen bei mir bei verschiedenen Records falsche werte an.

Die Functionen.
t_TagsLibrary_GetAudioAttributes = function (Tags: HTags; AudioType: TAudioType; Attributes: Pointer): LongBool; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
Code:
Public Declare Function TagsLibrary_GetAudioAttributes Lib "TagsLib.dll" (ByVal Tags As Long, ByVal AudioType As TAudioType, ByRef Attributes As Any) As Long
Die erste Type/Record.
Delphi-Quellcode:
type
    PAudioAttributes = ^TAudioAttributes;
    TAudioAttributes = packed record
        Channels: DWord; // number of channels (i.e. mono, stereo, etc.)
        SamplesPerSec: DWord; //sample rate
        BitsPerSample: DWord; //number of bits per sample of mono data
        PlayTime: Double;
        SampleCount: UInt64;
        BitRate: Integer;
    end;
Code:
Public Type TAudioAttributes
    Channels     As Long     ' number of channels (i.e. mono, stereo, etc.)
    SamplesPerSec As Long     ' sample rate
    BitsPerSample As Long     ' number of bits per sample of mono data
    PlayTime     As Double   ' duration in seconds
    SampleCount  As Currency ' number of total samples
    Bitrate      As Long
End Type
Die abfrage function
Code:
Public Sub GetAudioAttributes(ByVal AudioType As TAudioType)

Dim AudioAttributes As TAudioAttributes

    If AudioType = atAutomatic Then
        TagsLibrary_GetAudioAttributes LngTags, AudioType, AudioAttributes

        AttributesChannels = AudioAttributes.Channels
        AttributesSamplesPerSec = AudioAttributes.SamplesPerSec
        AttributesBitsPerSample = AudioAttributes.BitsPerSample
        AttributesPlayTime = AudioAttributes.PlayTime
        AttributesSampleCount = AudioAttributes.SampleCount
        AttributesBitrate = AudioAttributes.Bitrate
    End If

End Sub
Werte werden richtig zurückgegeben.

zweite Record
Delphi-Quellcode:
type
    PMPEGAudioAttributes = ^TMPEGAudioAttributes;
    TMPEGAudioAttributes = packed record
        Position: Int64; //* Position of header in bytes
        Header: DWord; //* The Headers bytes
        FrameSize: Integer; //* Frame's length
        Version: TMPEGVersion; //* MPEG Version
        Layer: TMPEGLayer; //* MPEG Layer
        CRC: LongBool; //* Frame has CRC
        BitRate: DWord; //* Frame's bitrate
        SampleRate: DWord; //* Frame's sample rate
        Padding: LongBool; //* Frame is padded
        _Private: LongBool; //* Frame's private bit is set
        ChannelMode: TMPEGChannelMode; //* Frame's channel mode
        ModeExtension: TMPEGModeExtension; //* Joint stereo only
        Copyrighted: LongBool; //* Frame's Copyright bit is set
        Original: LongBool; //* Frame's Original bit is set
        Emphasis: TMPEGEmphasis; //* Frame's emphasis mode
        VBR: LongBool; //* Stream is probably VBR
        FrameCount: Int64; //* Total number of MPEG frames (by header)
        Quality: Integer; //* MPEG quality
        Bytes: Int64; //* Total bytes
    end;
Code:
Public Type TMPEGAudioAttributes
    Position     As Currency              '* Position of header in bytes
    Header       As Long                  '* The Headers bytes
    FrameSize    As Long                  '* Frame's length
    Version      As TMPEGVersion          '* MPEG Version
    Layer        As TMPEGLayer            '* MPEG Layer
    CRC          As Long                  '* Frame has CRC
    Bitrate      As Long                  '* Frame's bitrate
    SampleRate   As Long                  '* Frame's sample rate
    Padding      As Long                  '* Frame is padded
    Private_      As Long                  '* Frame's private bit is set
    ChannelMode  As TMPEGChannelMode      '* Frame's channel mode
    ModeExtension As TMPEGModeExtension    '* Joint stereo only
    Copyrighted  As Long                  '* Frame's Copyright bit is set
    Original     As Long                  '* Frame's Original bit is set
    Emphasis     As TMPEGEmphasis         '* Frame's emphasis mode
    VBR          As Long                  '* Stream is probably VBR
    FrameCount   As Currency              '* Total number of MPEG frames (by header)
    Quality      As Long                  '* MPEG quality
    Bytes        As Currency              '* Total bytes
End Type
Die abfrage function
Code:
Public Sub GetMPEGAudioAttributes(ByVal AudioType As TAudioType)

Dim MPGAudioAttributes As TMPEGAudioAttributes

    If AudioType = atMPEG Then
        TagsLibrary_GetAudioAttributes LngTags, AudioType, MPGAudioAttributes

        MPGAttributesPosition = MPGAudioAttributes.Position
        MPGAttributesHeader = MPGAudioAttributes.Header
        MPGAttributesFrameSize = MPGAudioAttributes.FrameSize
        MPGAttributesVersion = MPGAudioAttributes.Version
        MPGAttributesLayer = MPGAudioAttributes.Layer
        MPGAttributesCRC = MPGAudioAttributes.CRC
        MPGAttributesBitrate = MPGAudioAttributes.Bitrate
        MPGAttributesSampleRate = MPGAudioAttributes.SampleRate
        MPGAttributesPadding = MPGAudioAttributes.Padding
        MPGAttributesPrivate_ = MPGAudioAttributes.Private_
        MPGAttributesChannelMode = MPGAudioAttributes.ChannelMode
        MPGAttributesModeExtension = MPGAudioAttributes.ModeExtension
        MPGAttributesCopyrighted = MPGAudioAttributes.Copyrighted
        MPGAttributesOriginal = MPGAudioAttributes.Original
        MPGAttributesEmphasis = MPGAudioAttributes.Emphasis
        MPGAttributesVBR = MPGAudioAttributes.VBR
        MPGAttributesFrameCount = MPGAudioAttributes.FrameCount
        MPGAttributesQuality = MPGAudioAttributes.Quality
        MPGAttributesBytes = MPGAudioAttributes.Bytes
    End If

End Sub
Wie man sehen kann sind beide abfragen (GetMPEGAudioAttributes\GetAudioAttributes) vom Aufbau gleich.
Trotzdem sind die Rückgabewerte von GetMPEGAudioAttributes falsch.

Kann mir nun jemand sagen woran das liegen könnte..
Warum sind die Abfragen beim ersten Record richtig und beim zweiten wiederum nicht!
Meine Vermutung ist das die Typen Int64 mit VB6 nicht kompatibel sind obwohl Currency und Int64 jeweils 8 Byte groß sind.

Hoffe das sich jemand die mühe macht das durchzulesen.

gruss

Geändert von EWeiss (22. Feb 2015 um 18:09 Uhr)
  Mit Zitat antworten Zitat