Sign in to follow this  
Followers 0
monoceres

IStream interface

12 posts in this topic




#2 ·  Posted (edited)

How do I use the IStream interface with autoit?

http://msdn.microsoft.com/en-us/library/aa380034(VS.85).aspx

I need it so I can get a stream object to a file which I can then pass to a method in a COM object.

Ideas?

:)

Here's an example. This is actually included as an undocumented procedure in IE.au3 in AutoIt V3.2.13.0. The two procedures convert strings to BSTR and BSTR to string for use in some COM functions - for example to use POST with IE navigation.

#cs
    #include <IE.au3>
    ; Simulates the submission of the form from the page:
    ;
    ;    http://www.autoitscript.com/forum/index.php?act=Search
    ;
    ; searches for the string safearray and returns the results as posts
    
    $sFormAction = "http://www.autoitscript.com/forum/index.php?act=Search&CODE=01"
    $sHeader = "Content-Type: application/x-www-form-urlencoded"
    
    $sDataToPost = "keywords=safearray&namesearch=&forums%5B%5D=all&searchsubs=1&prune=0&prune_type=newer&sort_key=last_post&sort_order=desc&search_in=posts&result_type=posts"
    $oDataToPostBstr = __IEStringToBstr($sDataToPost) ; convert string to BSTR
    ConsoleWrite(__IEBstrToString($oDataToPostBstr) & @CR) ; prove we can convert it back to a string
    
    $oIE = _IECreate()
    $oIE.Navigate( $sFormAction, Default, Default, $oDataToPostBstr, $sHeader)
    ; or
    ;__IENavigate($oIE, $sFormAction, 1, 0, "", $oDataToPostBstr, $sHeader)
#ce

Func __IEStringToBstr($s_string, $s_charSet = "us-ascii")
    Local Const $adTypeBinary = 1, $adTypeText = 2
    Local $o_Stream

    $o_Stream = ObjCreate("ADODB.Stream")
    
    $o_Stream.Type = $adTypeText
    $o_Stream.CharSet = $s_charSet
    $o_Stream.Open
    $o_Stream.WriteText($s_string)
    $o_Stream.Position = 0
    
    $o_Stream.Type = $adTypeBinary
    $o_Stream.Position = 0
    
    Return $o_Stream.Read
EndFunc   ;==>__IEStringToBstr

Func __IEBstrToString($o_bstr, $s_charSet = "us-ascii")
    Local Const $adTypeBinary = 1, $adTypeText = 2
    Local $o_Stream

    $o_Stream = ObjCreate("ADODB.Stream")
    
    $o_Stream.Type = $adTypeBinary
    $o_Stream.Open
    $o_Stream.Write($o_bstr)
    $o_Stream.Position = 0
    
    $o_Stream.Type = $adTypeText
    $o_Stream.CharSet = $s_charSet
    $o_Stream.Position = 0
    
    Return $o_Stream.ReadText
EndFunc   ;==>__IEBstrToString

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

What is the ultimate goal? It may be easier to come up with something if we know the task.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@ DaleHohm

Thanks for the code, I will study it and see if I can make it work in my code :)

@ weaponx

I'm currently working on a IMAPI2 UDF (cd and dvd burning (http://msdn.microsoft.com/en-us/library/aa366450(VS.85).aspx)) and all is going well.

I already have working functions that let you burn cds and dvds.

But to burn and create iso files you need to pass a valid IStream object to the iso file you wanna use to the burning methods.

Here's how someone did it in vbs: http://www.bokebb.com/dev/english/2057/pos...057141579.shtml

But I cannot find any documentation on the weird "fnCreateStreamFromFile()" function he uses.

Thanks for the input :P

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

@ DaleHohm

Thanks for the code, I will study it and see if I can make it work in my code :)

@ weaponx

I'm currently working on a IMAPI2 UDF (cd and dvd burning (http://msdn.microsoft.com/en-us/library/aa366450(VS.85).aspx)) and all is going well.

I already have working functions that let you burn cds and dvds.

But to burn and create iso files you need to pass a valid IStream object to the iso file you wanna use to the burning methods.

Here's how someone did it in vbs: http://www.bokebb.com/dev/english/2057/pos...057141579.shtml

But I cannot find any documentation on the weird "fnCreateStreamFromFile()" function he uses.

Thanks for the input :P

ProgAndy also used streams here.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Maybe you could use SHCreateStreamOnFile to get the Stream :)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Maybe you could use SHCreateStreamOnFile to get the Stream :)

Thanks, I managed to get a stream with that (I think) but it still doesn't work :P

Here's my test code:

; Recorder have to have empty disc media, else fail

; Test writing a iso file
$discmaster = ObjCreate("IMAPI2.MsftDiscMaster2")
$id = $discmaster.Item(0)
$recorder = ObjCreate("IMAPI2.MsftDiscRecorder2")
$recorder.InitializeDiscRecorder($id)
$writer = ObjCreate("IMAPI2.MsftDiscFormat2Data")
$writer.recorder = $recorder
$writer.ClientName = @AutoItVersion
Dim $ptr
$stream = DllCall("shlwapi.dll", "int", "SHCreateStreamOnFile", "str", "C:\Image.iso", "dword", 0, "ptr*", $ptr)
$ptr = $stream[3]
$writer.write($ptr)

:P


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Thanks, I managed to get a stream with that (I think) but it still doesn't work :P

Here's my test code:

; Recorder have to have empty disc media, else fail

; Test writing a iso file
$discmaster = ObjCreate("IMAPI2.MsftDiscMaster2")
$id = $discmaster.Item(0)
$recorder = ObjCreate("IMAPI2.MsftDiscRecorder2")
$recorder.InitializeDiscRecorder($id)
$writer = ObjCreate("IMAPI2.MsftDiscFormat2Data")
$writer.recorder = $recorder
$writer.ClientName = @AutoItVersion
Dim $ptr
$stream = DllCall("shlwapi.dll", "int", "SHCreateStreamOnFile", "str", "C:\Image.iso", "dword", 0, "ptr*", $ptr)
$ptr = $stream[3]
$writer.write($ptr)

:)

You are not passing a pointer to a pointer there, you will just be passing the value of $ptr which will be 0 I think.

Maybe that should be more like

; Recorder have to have empty disc media, else fail

; Test writing a iso file
$discmaster = ObjCreate("IMAPI2.MsftDiscMaster2")
$id = $discmaster.Item(0)
$recorder = ObjCreate("IMAPI2.MsftDiscRecorder2")
$recorder.InitializeDiscRecorder($id)
$writer = ObjCreate("IMAPI2.MsftDiscFormat2Data")
$writer.recorder = $recorder
$writer.ClientName = @AutoItVersion
Dim $ptr
$ptr = DllStructCreate("ptr")
$stream = DllCall("shlwapi.dll", "int", "SHCreateStreamOnFile", "str", "C:\Image.iso", "dword", 0, "ptr", DllStructGetPtr($ptr))
$ptr1 = DllStructGetData($ptr)
$writer.write($ptr1)

The notes on msdn say that you should use SHCreateStreamOnFileEx now btw.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You are not passing a pointer to a pointer there, you will just be passing the value of $ptr which will be 0 I think.

Maybe that should be more like

; Recorder have to have empty disc media, else fail
 
; Test writing a iso file
 $discmaster = ObjCreate("IMAPI2.MsftDiscMaster2")
 $id = $discmaster.Item(0)
 $recorder = ObjCreate("IMAPI2.MsftDiscRecorder2")
 $recorder.InitializeDiscRecorder($id)
 $writer = ObjCreate("IMAPI2.MsftDiscFormat2Data")
 $writer.recorder = $recorder
 $writer.ClientName = @AutoItVersion
 Dim $ptr
 $ptr = DllStructCreate("ptr")
 $stream = DllCall("shlwapi.dll", "int", "SHCreateStreamOnFile", "str", "C:\Image.iso", "dword", 0, "ptr", DllStructGetPtr($ptr))
 $ptr1 = DllStructGetData($ptr)
 $writer.write($ptr1)

The notes on msdn say that you should use SHCreateStreamOnFileEx now btw.

Sorry but DllStructGetData needs another parameter and I'm afraid I don't know what to put into that. As far as I know we haven't created anything in the struct, just a nameless pointer or something :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Sorry but DllStructGetData needs another parameter and I'm afraid I don't know what to put into that. As far as I know we haven't created anything in the struct, just a nameless pointer or something :)

Sorry, it should be

DllStructGetData($ptr,1)

We haven't put anything there. We passed a pointer to the fuction to show where the variable is stored, then the function writes the value to that variable then we can read it with dllstructgetdata.

The last parameter should be

IStream **ppstm

which is a pointer to a pointer I think, and the code I gave was my attempt to do that but it might be wrong.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Sorry, it should be

DllStructGetData($ptr,1)

We haven't put anything there. We passed a pointer to the fuction to show where the variable is stored, then the function writes the value to that variable then we can read it with dllstructgetdata.

The last parameter should be

which is a pointer to a pointer I think, and the code I gave was my attempt to do that but it might be wrong.

I think that **ppstm means a pointer that is passed by reference or something, the thing is that I think my original way actually did work in some way because $ptr was getting a pointer that pointed to something.

I guess this is why most modern programming languages hides pointers :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

I think that **ppstm means a pointer that is passed by reference or something, the thing is that I think my original way actually did work in some way because $ptr was getting a pointer that pointed to something.

I guess this is why most modern programming languages hides pointers :)

I suppose that's right but you pass by reference by giving the address of the variable. So if you pass a pointer by reference then it's a pointer to a pointer. The value you passed was $ptr which would have been 0 so I didn't think that would work. What I tried to do was to pass the address of where the pointer was stored.

Maybe it should be

..."ptr*",DllStructGetPtr($prt))

But since I don't really know I don't want to waste your time with endless suggestions.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0