Page 1 of 1

ADODB.Stream from file ? [for burning with pb]

Posted: Wed Jul 04, 2007 7:05 pm
by bingo
my pb skeleton ... 8)

Code: Select all

;ADODB.Stream

Interface _Stream Extends IDispatch
  get_Size(a)
  get_EOS(a)
  get_Position(a)
  put_Position(a)
  get_Type(a)
  put_Type(a)
  get_LineSeparator(a)
  put_LineSeparator(a)
  get_State(a)
  get_Mode(a)
  put_Mode(a)
  get_Charset(a)
  put_Charset(a)
  Read(a,b)
  Open(a,b,c,d,e)
  Close()
  SkipLine()
  Write(a,b,c,d)
  SetEOS()
  CopyTo(a,b)
  Flush()
  SaveToFile(a,b)
  LoadFromFile(a)
  ReadText(a,b)
  WriteText(a,b)
  Cancel()
EndInterface


CoInitialize_(0) 
If CoCreateInstance_(?CLSID_Stream,0,1,?IID__Stream,@object._Stream) = 0 

;object\open(???)
;object\LoadFromFile(???)

object\release()

EndIf

CoUninitialize_()

End

DataSection
CLSID_Stream:
Data.l $00000566
Data.w $0000,$0010
Data.b $80,$00,$00,$AA,$00,$6D,$2E,$A4
IID__Stream:
Data.l $00000565
Data.w $0000,$0010
Data.b $80,$00,$00,$AA,$00,$6D,$2E,$A4
EndDataSection

any hints how to handle the

object\open(...)
object\LoadFromFile(...) :?:


I would like to translate this (vbs) vista script in pb4 ...

' This script burns a boot image and data files to disc in a
' single session using files from a single directory tree.

'Copyright (C) Microsoft Corp. 2006

Option Explicit

' *** CD/DVD disc file system types
Const FsiFileSystemISO9660 = 1
Const FsiFileSystemJoliet = 2
Const FsiFileSystemUDF = 4

WScript.Quit(Main)

Function Main
Dim index ' Index to recording drive.
Dim recorder ' Recorder object
Dim path ' Directory of files to burn
Dim stream ' Data stream for burning device
Dim bootFile ' Path and filename of boot image

index = 0 ' first drive on the system
path = "c:\burn"
bootFile = "c:\burn\freedos.ima"

' Create a DiscMaster2 object to connect to CD/DVD drives.
Dim g_DiscMaster
Set g_DiscMaster = WScript.CreateObject("IMAPI2.MsftDiscMaster2")

' Create a DiscRecorder object for the specified burning device.
Dim uniqueId
set recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
uniqueId = g_DiscMaster.Item(index)
recorder.InitializeDiscRecorder( uniqueId )

' -------- Adding Boot Image Code -----
Dim bootOptions
WScript.Echo "Creating BootOptions"
SET bootOptions = WScript.CreateObject("IMAPI2FS.BootOptions")
bootOptions.Manufacturer = "Microsoft"
bootOptions.PlatformId = 0 ' x86 family processor
bootOptions.Emulation = 0 ' EmulationType.EmulationNone

' Need a stream for the boot image file
Const adFileTypeBinary = 1
DIM bootStream
Set bootStream = CreateObject("ADODB.Stream")
WScript.Echo "Creating IStream for file " + bootFile
bootStream.Open
bootStream.Type = adFileTypeBinary
bootStream.LoadFromFile bootFile
bootOptions.AssignBootImage(bootStream)

' Create disc file system image (ISO9660 in this example)
Dim FSI
SET FSI = WScript.CreateObject("IMAPI2FS.MsftFileSystemImage")
FSI.FreeMediaBlocks = 0 ' Enables larger-than-CD image
FSI.FileSystemsToCreate = FsiFileSystemISO9660

' Add the boot directory and its contents to the file system
FSI.BootImageOptions = bootOptions

' Add the content directory and files to the file system
FSI.root.AddTree path, FALSE

Dim result
Set result = FSI.CreateResultImage()
stream = result.ImageStream

' Create and write stream to disc using the specified recorder.
Dim dataWriter
Set dataWriter = CreateObject("IMAPI2.MsftDiscFormat2Data")
dataWriter.recorder = Recorder
dataWriter.ClientName = "IMAPIv2 TEST"

dataWriter.write(stream)
WScript.Echo "----- Finished writing content -----"

Main = 0
End Function

Posted: Wed Jul 04, 2007 11:36 pm
by Flype
this is a sample of the msdn c++ documentation

Code: Select all

Methods

Cancel(void)

Close(void)

CopyTo(_ADOStream *DestStream, LONG CharNumber = -1)

Flush(void)

LoadFromFile(BSTR FileName)

Open(VARIANT Source, ConnectModeEnum Mode, StreamOpenOptionsEnum Options,
         BSTR UserName, BSTR Password)

Read(long NumBytes, VARIANT *pVal)

ReadText(long NumChars, BSTR *pbstr)

SaveToFile(BSTR FileName, SaveOptionsEnum Options = adSaveCreateNotExist)

SetEOS(void)

SkipLine(void)

Write(VARIANT Buffer)

WriteText(BSTR Data, StreamWriteEnum Options = adWriteChar)
Properties

get_Charset(BSTR *pbstrCharset)
put_Charset(BSTR Charset)

get_EOS(VARIANT_BOOL *pEOS)

get_LineSeparator(LineSeparatorEnum *pLS)
put_LineSeparator(LineSeparatorEnum LineSeparator)

get_Mode(ConnectModeEnum *pMode)
put_Mode(ConnectModeEnum Mode)

get_Position(LONG *pPos)
put_Position(LONG Position)

get_Size(LONG *pSize)

get_State(ObjectStateEnum *pState)

get_Type(StreamTypeEnum *pType)
put_Type(StreamTypeEnum Type)
as you can see, LoadFromFile(BSTR FileName) require a BSTR string as argument.

so in purebasic you 'should' (there are some others methods) specify it as this :

c++
LoadFromFile(BSTR FileName)

purebasic
LoadFromFile(FileName.p-bstr)

this allow to directly write in your code LoadFromFile("c:\myfilename.file").

not tested, it should work.

Posted: Thu Jul 05, 2007 5:23 pm
by bingo
a other stream way with CreateStreamOnHGlobal ...

a vista burning sample . create a bootdisc-image (freedos...) with winimage and include the binary in this exe . the image is burned now on the CD/DVD as "bootable".

... but "interfaces" is a horror :shock:

Code: Select all

Interface IBootOptions ; Boot options 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_BootImage(dispidMember.l) 
  get_Manufacturer(dispidMember.l) 
  put_Manufacturer(dispidMember.p-bstr) 
  get_PlatformId(dispidMember.l) 
  put_PlatformId(dispidMember.l) 
  get_Emulation(dispidMember.l) 
  put_Emulation(dispidMember.l) 
  get_ImageSize(dispidMember.l) 
  AssignBootImage(newVal.l) 
EndInterface 

Interface IDiscMaster2 Extends IDispatch 
  get__NewEnum(a) 
  get_Item(a,b) 
  get_Count(a) 
  get_IsSupportedEnvironment(a) 
EndInterface 

Interface IDiscRecorder2 Extends IDispatch 
  EjectMedia() 
  CloseTray() 
  AcquireExclusiveAccess(a,b) 
  ReleaseExclusiveAccess() 
  DisableMcn() 
  EnableMcn() 
  InitializeDiscRecorder(a) 
  get_ActiveDiscRecorder(a) 
  get_VendorId(a) 
  get_ProductId(a) 
  get_ProductRevision(a) 
  get_VolumeName(a) 
  get_VolumePathNames(a) 
  get_DeviceCanLoadMedia(a) 
  get_LegacyDeviceNumber(a) 
  get_SupportedFeaturePages(a) 
  get_CurrentFeaturePages(a) 
  get_SupportedProfiles(a) 
  get_CurrentProfiles(a) 
  get_SupportedModePages(a) 
  get_ExclusiveAccessOwner(a) 
EndInterface 

Interface IFileSystemImage ; File system image 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_Root(dispidMember.l) 
  get_SessionStartBlock(dispidMember.l) 
  put_SessionStartBlock(dispidMember.l) 
  get_FreeMediaBlocks(dispidMember.l) 
  put_FreeMediaBlocks(dispidMember.l) 
  SetMaxMediaBlocksFromDevice(discRecorder.l) 
  get_UsedBlocks(discRecorder.l) 
  get_VolumeName(discRecorder.l) 
  put_VolumeName(discRecorder.p-bstr) 
  get_ImportedVolumeName(discRecorder.l) 
  get_BootImageOptions(discRecorder.l) 
  put_BootImageOptions(discRecorder.l) 
  get_FileCount(discRecorder.l) 
  get_DirectoryCount(discRecorder.l) 
  get_WorkingDirectory(discRecorder.l) 
  put_WorkingDirectory(discRecorder.p-bstr) 
  get_ChangePoint(discRecorder.l) 
  get_StrictFileSystemCompliance(discRecorder.l) 
  put_StrictFileSystemCompliance(discRecorder.w) 
  get_UseRestrictedCharacterSet(discRecorder.l) 
  put_UseRestrictedCharacterSet(discRecorder.w) 
  get_FileSystemsToCreate(discRecorder.l) 
  put_FileSystemsToCreate(discRecorder.l) 
  get_FileSystemsSupported(discRecorder.l) 
  put_UDFRevision(discRecorder.l) 
  get_UDFRevision(discRecorder.l) 
  get_UDFRevisionsSupported(discRecorder.l) 
  ChooseImageDefaults(discRecorder.l) 
  ChooseImageDefaultsForMediaType(value.l) 
  put_ISO9660InterchangeLevel(value.l) 
  get_ISO9660InterchangeLevel(value.l) 
  get_ISO9660InterchangeLevelsSupported(value.l) 
  CreateResultImage(a.l) 
  Exists(FullPath.p-bstr) 
  CalculateDiscIdentifier() 
  IdentifyFileSystemsOnDisc(discRecorder.l) 
  GetDefaultFileSystemForImport(fileSystems.l) 
  ImportFileSystem() 
  ImportSpecificFileSystem(fileSystemToUse.l) 
  RollbackToChangePoint(ChangePoint.l) 
  LockInChangePoint() 
  CreateDirectoryItem(Name.p-bstr) 
  CreateFileItem(Name.p-bstr) 
  get_VolumeNameUDF(Name.l) 
  get_VolumeNameJoliet(Name.l) 
  get_VolumeNameISO9660(Name.l) 
  get_StageFiles(Name.l) 
  put_StageFiles(Name.w) 
  get_MultisessionInterfaces(Name.l) 
  put_MultisessionInterfaces(Name.l) 
EndInterface 

Interface IFileSystemImageResult ; FileSystemImage result stream 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_ImageStream(dispidMember.l) 
  get_ProgressItems(dispidMember.l) 
  get_TotalBlocks(dispidMember.l) 
  get_BlockSize(dispidMember.l) 
  get_DiscId(dispidMember.l) 
EndInterface 

Interface IDiscFormat2Data ; Data Writer 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  IsRecorderSupported(Recorder.l) 
  IsCurrentMediaSupported(Recorder.l) 
  get_MediaPhysicallyBlank(Recorder.l) 
  get_MediaHeuristicallyBlank(Recorder.l) 
  get_SupportedMediaTypes(Recorder.l) 
  put_Recorder(Recorder.l) 
  get_Recorder(Recorder.l) 
  put_BufferUnderrunFreeDisabled(Recorder.w) 
  get_BufferUnderrunFreeDisabled(Recorder.l) 
  put_PostgapAlreadyInImage(Recorder.w) 
  get_PostgapAlreadyInImage(Recorder.l) 
  get_CurrentMediaStatus(Recorder.l) 
  get_WriteProtectStatus(Recorder.l) 
  get_TotalSectorsOnMedia(Recorder.l) 
  get_FreeSectorsOnMedia(Recorder.l) 
  get_NextWritableAddress(Recorder.l) 
  get_StartAddressOfPreviousSession(Recorder.l) 
  get_LastWrittenAddressOfPreviousSession(Recorder.l) 
  put_ForceMediaToBeClosed(Recorder.w) 
  get_ForceMediaToBeClosed(Recorder.l) 
  put_DisableConsumerDvdCompatibilityMode(Recorder.w) 
  get_DisableConsumerDvdCompatibilityMode(Recorder.l) 
  get_CurrentPhysicalMediaType(Recorder.l) 
  put_ClientName(Recorder.p-bstr) 
  get_ClientName(Recorder.l) 
  get_RequestedWriteSpeed(Recorder.l) 
  get_RequestedRotationTypeIsPureCAV(Recorder.l) 
  get_CurrentWriteSpeed(Recorder.l) 
  get_CurrentRotationTypeIsPureCAV(Recorder.l) 
  get_SupportedWriteSpeeds(Recorder.l) 
  get_SupportedWriteSpeedDescriptors(Recorder.l) 
  put_ForceOverwrite(Recorder.w) 
  get_ForceOverwrite(Recorder.l) 
  get_MultisessionInterfaces(Recorder.l) 
  Write(Data_.l) 
  CancelWrite() 
  SetWriteSpeed(RequestedSectorsPerSecond.l,RotationTypeIsPureCAV.w) 
EndInterface 

pp.variant 
pp\vt = #VT_BSTR 

CreateStreamOnHGlobal_(0,#True,@stream.IStream) 
stream\write(?test1a,?test1e-?test1a, @dwWritten.l) 

CoInitialize_(0) 
If CoCreateInstance_(?CLSID_BootOptions,0,1,?IID_IBootOptions,@object_boot.IBootOptions) = 0 
object_boot\put_Manufacturer("Microsoft") 
object_boot\put_PlatformId(0) ;x86 family processor 
object_boot\put_Emulation(0)  ;EmulationType.EmulationNone 
object_boot\AssignBootImage(Stream.IStream) 

If CoCreateInstance_(?CLSID_MsftDiscMaster2,0,1,?IID_IDiscMaster2,@object_disc.IDiscMaster2) = 0 
object_disc\get_Item(0,@pp\bstrval) ; 1. burner 

If CoCreateInstance_(?CLSID_MsftDiscRecorder2,0,1,?IID_IDiscRecorder2,@object_record.IDiscRecorder2) = 0 
object_record\InitializeDiscRecorder(pp\bstrval) 

If CoCreateInstance_(?CLSID_FileSystemImage,0,1,?IID_IFileSystemImage,@object_fsimage.IFileSystemImage) = 0 

object_fsimage\put_FreeMediaBlocks(0) ;Enables larger-than-CD image 
object_fsimage\put_FileSystemsToCreate(1) ;FsiFileSystemISO9660 
object_fsimage\put_BootImageOptions(object_boot.IBootOptions) 

object_fsimage\CreateResultImage(@result.IFileSystemImageResult) 

result\get_ImageStream(@iistream.l) 

If CoCreateInstance_(?CLSID_DiscFormat2Data,0,1,?IID_IDiscFormat2Data,@object_format.IDiscFormat2Data) = 0 

object_format\put_Recorder(object_record) 
object_format\put_ClientName("burn test") 
object_format\write(iistream) 

object_format\release() 
EndIf 

object_fsimage\release() 
EndIf 

object_record\release() 
EndIf 

object_disc\release() 
EndIf 

object_boot\Release() 
EndIf 

CoUninitialize_() 

stream\Release() 
End 


DataSection 

test1a: 
IncludeBinary "c:\burn\freedos.ima" 
test1e: 

CLSID_DiscFormat2Data: 
Data.l $2735412A 
Data.w $7F64,$5B0F 
Data.b $8F,$00,$5D,$77,$AF,$BE,$26,$1E 

IID_IDiscFormat2Data: 
Data.l $27354153 
Data.w $9F64,$5B0F 
Data.b $8F,$0,$5D,$77,$AF,$BE,$26,$1E 

CLSID_FileSystemImage: 
Data.l $2C941FC5 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 

IID_IFileSystemImage: 
Data.l $2C941FE1 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 

CLSID_MsftDiscRecorder2: 
Data.l $2735412D 
Data.w $7F64,$5B0F 
Data.b $8F,$0,$5D,$77,$AF,$BE,$26,$1E 

IID_IDiscRecorder2: 
Data.l $27354133 
Data.w $7F64,$5B0F 
Data.b $8F,$0,$5D,$77,$AF,$BE,$26,$1E 

CLSID_MsftDiscMaster2: 
Data.l $2735412E 
Data.w $7F64,$5B0F 
Data.b $8F,$0,$5D,$77,$AF,$BE,$26,$1E 

IID_IDiscMaster2: 
Data.l $27354130 
Data.w $7F64,$5B0F 
Data.b $8F,$0,$5D,$77,$AF,$BE,$26,$1E 
    
CLSID_BootOptions: 
Data.l $2C941FCE 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 

IID_IBootOptions: 
Data.l $2C941FD4 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 


EndDataSection
more ... http://msdn2.microsoft.com/en-us/library/aa366224.aspx

Posted: Wed Jan 09, 2008 4:12 am
by SFSxOI
Can someone explain this to me please:

Code: Select all

stream\write(?test1a,?test1e-?test1a, @dwWritten.l)
I understand what its supposed to do I just don't fully understand how it does it with the test1e item in the data section.

I see the test1a in the data section but what does the test1e- do here and how does it work?

Is there a way to write this so the data section entry isn't needed and the ima can be included as a variable??

Posted: Sat Jan 12, 2008 2:22 pm
by SFSxOI
I was looking for a better way other then to have another interface or another addition to the datasection, I found this works:

Code: Select all

BootImg.IStream

file_boot$ = "C:\boot\bootimage.bin"
SHCreateStreamOnFileEx(file_boot$,#STGM_READ|#STGM_SHARE_DENY_NONE,0,0,0,@BootImg)


;And then:

If CoCreateInstance_(?CLSID_BootOptions,0,1,?IID_IBootOptions,@BOOTOBJ.IBootOptions) = 0 ; boot image code
  BOOTOBJ\put_Manufacturer("Microsoft") 
  BOOTOBJ\put_PlatformId(0) ;x86 family processor 
  BOOTOBJ\put_Emulation(0)  ;EmulationType.EmulationNone
  BOOTOBJ\AssignBootImage(BootImg)
and this works too:

Code: Select all

BootImg.IStream

file_boot$ = "My_boot_file.bin"
CreateStreamOnHGlobal_(0,#True,@BootImg)

    If ReadFile(0, file_boot$) 
    length = Lof(0)                            ; get the length of opened file
    *BootID = AllocateMemory(length)         ; allocate the needed memory    If *BootID
    bytes = ReadData(0, *BootID, length)   ; read all data into the memory block
    Debug "Number of bytes read: " + Str(bytes)
    BootImg\Write(*BootID, bytes-0, @dwCount.l)
    Debug "bytes written:   " +Str(dwCount)
    EndIf
  CloseFile(0)

and then,,,,,

And then: 

If CoCreateInstance_(?CLSID_BootOptions,0,1,?IID_IBootOptions,@BOOTOBJ.IBootOptions) = 0 ; boot image code 
  BOOTOBJ\put_Manufacturer("Microsoft") 
  BOOTOBJ\put_PlatformId(0) ;x86 family processor 
  BOOTOBJ\put_Emulation(0)  ;EmulationType.EmulationNone 
  BOOTOBJ\AssignBootImage(BootImg)