New topic: vb6 to RB / byte array
<http://forums.realsoftware.com/viewtopic.php?t=30601> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message offlinebouncer Post subject: vb6 to RB / byte arrayPosted: Thu Oct 22, 2009 10:14 am Joined: Tue Sep 22, 2009 2:27 pm Posts: 16 I need to convert the following to RB: Code: Dim bChar() As Byte Dim lFileLenght As Long Open App.Path & "\input.pdf" For Binary As #1 lFileLenght = LOF(1) ReDim bChar(lFileLenght - 1) Get #1, , bChar Close #1 ViewerControl.OpenMem bChar, "" The plugin wants a byte-array. How can this be done in RB?? Top Phil M Post subject: Re: vb6 to RB / byte arrayPosted: Thu Oct 22, 2009 10:35 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 190 REALbasic you can also create: Dim bChar( ) As Byte But thats not the typical way you want to work with things in REALbasic (we are beyond such simple things as char pointers). I have no idea what ViewerControl.OpenMem is suppose to do, so this is just a guess, but you can probably rewrite the code like this: Code:Dim bChar As MemoryBlock Dim iFileLength As Long Dim f As FolderItem Dim bstream As BinaryStream #If TargetWin32 f = App.ExecutableFile.Parent.Child( myAppName + " Libs" ) If Not ( f Is Nil ) And f.Exists Then f = f.Child( "input.pdf" ) #Else TargetMacOS f = App.ExecutableFile.Child( "Contents" ).Child( "Resources" ).Child( "input.pdf" ) #Endif If Not ( f Is Nil ) And f.Exists Then bstream = BinaryStream.Open( f, False ) // false for read only If Not ( bstream Is Nil ) bChar = bstream.Read( bstream.Length ) // copy all data from file into memoryblock Else MsgBox "cannot locate the file 'input.pdf'" End If If Not ( bChar Is Nil ) Then ViewerControl.OpenMem( bChar ) Else ViewerControl.OpenMem( "" ) If you are creating ViewerControl.OpenMem as well, then you can tell it to accept the BinaryStream directly. But since you are saying its a plugin, then the code above should work because a MemoryBlock is very similar to the byte array as far as the plugin is concerned. Top offlinebouncer Post subject: Re: vb6 to RB / byte arrayPosted: Thu Oct 22, 2009 1:56 pm Joined: Tue Sep 22, 2009 2:27 pm Posts: 16 I already tried it that way, the plugin reports a ole-exception "can't read data" and exits Top jefftullin Post subject: Re: vb6 to RB / byte arrayPosted: Thu Oct 22, 2009 2:47 pm Joined: Wed Nov 15, 2006 3:50 pm Posts: 862 Try reading into a memoryblock of the right size and passing that instead. But I'm suspicious of the call Code:ViewerControl.OpenMem bChar, "" Either ViewerControl fully understands PDF files and knows how long they are in bytes based on the contents of the header, OR you should be passing the length of the byte array as a parameter. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
