Question about FourCCs and ICOpen function-VBForums
Results 1 to 3 of 3

Thread: Question about FourCCs and ICOpen function

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    909

    Question about FourCCs and ICOpen function

    According to https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx there are 3 fields to ICOpen, the first of which requires an "type" FourCC to tell it what type of compressor (audio or video) is being requested for opening. If it's video, it must have the FourCC "VIDC" according to MSDN, but MSDN never tells the proper way to convert this string to a number. Notice that the FourCCs in ICOpen require a 4byte integer for input, not a four character string. So there's 2 possible ways to convert the string "VIDC" to an integer.

    1:
    Treat the string in memory as if it is an integer. The leftmost character corresponds to the least significant byte of the integer. For "VIDC", this corresponds to the integer 0x43444956

    2:
    Treat the string as if it is a number being displayed, with the leftmost character corresponding to the most significant byte of the value. For "VIDC", this corresponds to the integer 0x56494443

    I'm not sure which way is the correct way to convert a string to a FourCC. I want to do it right, so I don't crash my program when it tries to execute ICOpen, as in VB6, any time you encounter an API error, the entire VB6 IDE crashes. Normally, if I was just working with pure VB functions, I'd just try both ways, to see which worked, but I'm working with API functions here and I don't want to crash the IDE.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,305

    Re: Question about FourCCs and ICOpen function

    I'd never heard of FourCCs or ICOpen but after web search and 30 seconds I was looking at an answer to your question. This thread is C# code rather than VB6 but it does show the right way to convert four characters to a 32-bit number in this context.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,322

    Re: Question about FourCCs and ICOpen function

    Quote Originally Posted by Ben321 View Post
    ... any time you encounter an API error, the entire VB6 IDE crashes.
    You may be thinking of subclassing, callbacks, etc. Most API calls don't causes crashes.

    In any case Microsoft documents the format: FOURCC Codes. The values are 32-bit unsigned integers and thus can fit into a VB6 Long.

    Here is a Form wrapped around a FourCC calculation function:

    Code:
    Option Explicit
    
    Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Addr As Long, ByRef RetVal As Long)
    
    Private Function FourCC(ByVal FourCCText As String) As Long
        FourCCText = StrConv(UCase$(FourCCText), vbFromUnicode)
        GetMem4 StrPtr(FourCCText), FourCC
    End Function
    
    Private Sub cmdCopy_Click()
        With Clipboard
            .Clear
            .SetText lblHex.Caption, vbCFText
        End With
    End Sub
    
    Private Sub txtFourCC_Change()
        With txtFourCC
            cmdCopy.Enabled = Len(.Text) = 4
            If cmdCopy.Enabled Then
                .Text = UCase$(.Text)
                .SelStart = 4
                lblHex.Caption = "&H" _
                               & Right$(String$(7, "0") & Hex$(FourCC(.Text)), 8)
            Else
                lblHex.Caption = vbNullString
            End If
        End With
    End Sub
    Name:  sshot.png
Views: 57
Size:  1.7 KB

    Calling it a "calculator" is a little grandiose, but you get the idea.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.