Vb6 code upgrade issues

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
My friend sent me a VB6 app which dumps JPEG files into a single file. It successfully upgraded, but it doesn't work. I believe the major problem is converting the old functions to System.IO or the My namespace, but I haven't found much info on doing that.

Here are the interesting bits of the code:

Includes, video header structure
VB.NET:
    Public fh As Integer
    Public framefh As Integer
    Public outquality As Integer
    Public result As String
    Public framecount

    Structure VIDEO_HEADER
        Dim magic As String
        Dim framecount As Long
        Dim samplesize As Integer
        Dim finalsample As Integer
        Dim frametype As Integer
        Dim reserved As String
    End Structure

The following code errors when dumping the structure header into the file:

VB.NET:
 fh = FreeFile()

        FileOpen(fh, path + "outfile.emc", OpenMode.Binary)

        Dim vidhead As New VIDEO_HEADER

        vidhead.magic = "EMC01000"

        vidhead.framecount = framecount

        vidhead.frametype = 0

        vidhead.samplesize = 0

        vidhead.finalsample = 0

        FilePutObject(fh, vidhead)

And the following code errors when dumping the current frame into the file:

VB.NET:
For i = 1 To framecount
            framefh = FreeFile()
            FileOpen(framefh, path + "framedump\" & i.ToString & ".jpg", OpenMode.Binary)
            Dim iFrameSize As Integer = LOF(framefh)
            FilePutObject(fh, iFrameSize)
            Dim inbuffer As String = Space(iFrameSize)
            FileGetObject(framefh, inbuffer)
            FileClose(framefh)
            FilePutObject(fh, inbuffer)
        Next


Can you help me? :p
 
First, why dont you take 10 images, dump them into a file using the old and new apps, and then compare the files in a hex editor?
 
The VB6 app works fine, but I've upgraded the code to VB.NET and the .NET app doesn't work. I riddled out as many errors as I could, and the above blocks are the bits where things go wrong. FileOpen() and FilePutObject() are decipricated, and using the My.Computer.Filesystem or System.IO replacements might be the fix, but I couldn't find functions which seemed to do the same thing.


- James
 
Thanks. I managed to port the first bit:

VB.NET:
            framefh = FreeFile()
            FileOpen(framefh, path + "framedump\" & i.ToString & ".jpg", OpenMode.Binary)
            Dim iFrameSize As Integer = LOF(framefh)
            FilePutObject(fh, iFrameSize)
            Dim inbuffer As String = Space(iFrameSize)

TO:

VB.NET:
            Dim x As New FileStream(path + "framedump\" + i.ToString + ".jpg", FileMode.Open)

            Dim iFrameSize As Long = x.Length
            x.WriteByte(iFrameSize)

            Dim inbuffer As String = Space(iFrameSize)

The next bit:

VB.NET:
FileGetObject(framefh, inbuffer)
VB.NET's description of this says "Reads data from an open disk file into a variable". The parameters are pretty simple:
FileNumber: Required. Any valid file number.
Value: Required. Valid variable name into which data is read.

I presume I need to use

VB.NET:
x.Read (..)

But it's asking for some parameters which I don't know the value of. They're:
array: When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offset: The byte offset in array at which the read bytes will be placed.
count: The maximum number of bytes to read.

What should I do now? :p

EDIT: For anyone who's interested, here are the two *full* versions. I removed the VB6 form designer stuff.

VB6: pastebin - collaborative debugging tool
VB.NET: pastebin - collaborative debugging tool

(There's a bit of stuff which controls FFMPEG to convert the movie to JPEG frames and alot of pointless defines, but once I get it working I'll clean it up.)
 
Last edited:
Back
Top