WinBatch® Technical Support Forum

Archived Boards => COM Automation and dotNet => Topic started by: Mogens Christensen on June 07, 2013, 07:52:02 AM

Title: How to create SAFEARRAY COM/ADO structure
Post by: Mogens Christensen on June 07, 2013, 07:52:02 AM
any examples of or refs to creating and populating SAFEARRAY structures? - there are a few examples of how to get arrays out of them, but I need to construct them in Winbatch.
Title: Re: How to create SAFEARRAY COM/ADO structure
Post by: Deana on June 07, 2013, 08:30:28 AM
Quote from: moc on June 07, 2013, 07:52:02 AM
any examples of or refs to creating and populating SAFEARRAY structures? - there are a few examples of how to get arrays out of them, but I need to construct them in Winbatch.

ObjectType can convert WIL arrays and binary buffers to variant safearrays of a specific type. Request conversion by prepending "ARRAY|" to the variant element type in the first parameter.  The function's second parameter should contain a WIL array, a Variant safearray or a binary buffer when using the "ARRAY|" specification. The special type specification "ARRAY|VARIANT" can be used to convert WIL arrays already containing multiple variant types into a safearrays of type VARIANT.

For example:
Code (winbatch) Select
totalfortunes=20
arrFortune=ArrDimension(totalfortunes)
arrFortune[0] = "All your hard work will soon pay off."
arrFortune[1] = "Winbatch will save you time."
arrFortune[2] = "Your present plans are going to succeed."
arrFortune[3] = "You will live a long time."
arrFortune[4] = "One learns when teaching others."
arrFortune[5] = "Success means competition."
arrFortune[6] = "Your example will inspire others."
arrFortune[7] = "One must be available, alert, active, and adaptable."
arrFortune[8] = "If you have many best friends, you have no friends."
arrFortune[9] = "Mountains can move, but not your character."
arrFortune[10]= "You are a great coder."
arrFortune[11]= "Concern yourself about others more than yourself."
arrFortune[12]= "Time is the wisest counsellor."
arrFortune[13]= "What you desire is always possible. It will come to you."
arrFortune[14]= "You are known to be quick in action and decisive."
arrFortune[15]= "You are open-minded and quick to make new friends."
arrFortune[16]= "A good laugh and a good cry both cleanse the mind."
arrFortune[17]= "Failure is the mother of success."
arrFortune[18]= "Now is the time to try something new."
arrFortune[19]= "An old pot is the best around the kitchen."

SafArrFortune = ObjectType( 'ARRAY|BSTR', arrFortune )

Exit





Title: Re: How to create SAFEARRAY COM/ADO structure
Post by: Mogens Christensen on June 12, 2013, 01:58:56 AM
 certthumbstring = ChrHexToString("0123456789ABCDEF0123456789ABCDEF01234567")
certthumbarray= ArrayFromStr(certthumbstring)
certthumbsafearray = ObjectType("ARRAY|UI1",certthumbarray)

but it fails with  WIL ERROR SUPPRESSED =>1702 (ObjectType: Unsupported variant-type)

and we get the same error with

certthumbstring = ChrHexToString("0123456789ABCDEF0123456789ABCDEF01234567")
certthumbsafearray = ObjectType("ARRAY|BSTR",certthumbstring)

- how should we construct the SAFEARRAY from a certificate thumb string like "12 34 56 78 90 AB CD EF ...."
Title: Re: How to create SAFEARRAY COM/ADO structure
Post by: td on June 12, 2013, 08:40:06 AM
Code (winbatch) Select

strTumb = "eb 67 70 54 7e 68 aa 88 c7 83 5d 8e ea 7c be 74 3f 93 ad 10"

hBytes = BinaryAlloc(StrLen(strTumb))
BinaryPokeHex(hBytes, 0, strTumb)
BinaryOleType( hBytes, 103 , 0, 0, 0)

; Just pass the buffer (hBytes) as a parameter to a method expecting
; a safearray of unsigned bytes.