WinBatch® Technical Support Forum

Archived Boards => COM Automation and dotNet => Topic started by: stanl on June 11, 2013, 05:36:12 AM

Title: WB2013 and Convert Class
Post by: stanl on June 11, 2013, 05:36:12 AM
Just wanted to know the caveats associated with exploring the .net Convert Class, i.e. convert to/from Base64 etc..

Title: Re: WB2013 and Convert Class
Post by: Deana on June 11, 2013, 08:03:17 AM
Quote from: stanl on June 11, 2013, 05:36:12 AM
Just wanted to know the caveats associated with exploring the .net Convert Class, i.e. convert to/from Base64 etc..

Not sure to be honest. I have never worked with that specific class. Maybe someone that has, will chime in.
Title: Re: WB2013 and Convert Class
Post by: stanl on June 11, 2013, 08:12:09 AM
Quote from: Deana on June 11, 2013, 08:03:17 AM
Not sure to be honest. I have never worked with that specific class. Maybe someone that has, will chime in.
Thanks. It looks easy. The basic class has methods that convert stuff, but when I looked at some C# and PS code it seems there are bit and array variables that have to be initialized and that looked a little intimidating as you had mentioned in a previous post I made to stay away from the CLR arrays.
Title: Re: WB2013 and Convert Class
Post by: td on June 11, 2013, 09:25:01 AM
Quote from: stanl on June 11, 2013, 08:12:09 AM
...
Thanks. It looks easy. The basic class has methods that convert stuff, but when I looked at some C# and PS code it seems there are bit and array variables that have to be initialized and that looked a little intimidating as you had mentioned in a previous post I made to stay away from the CLR arrays.

Generally, WIL arrays work as [in] parameters to CLR methods or property assignments.  If you have a WIL array of numbers and the CLR method parameter is expecting something other than 4 byte intenger elements you may have to use ObjectType. For example, if an parameter is expecting an array of signed bytes you might need to do something like the following

Code (winbatch) Select

aBytes = ArrDimension(2)
aBytes[0] = 1
aBytes[1] = 2

saBytes = ObjectType("array|i1", aBytes)

before you pass the array to the method. 

The only other caveat is you cannot call methods that fill an array parameter with values.  This is because WinBatch does not support [out] parameters for CLR class methods.

Title: Re: WB2013 and Convert Class
Post by: stanl on June 11, 2013, 11:10:20 AM
Quote from: td on June 11, 2013, 09:25:01 AM
This is because WinBatch does not support [out] parameters for CLR class methods.

So this is a no-go?
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx (http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx)
Title: Re: WB2013 and Convert Class
Post by: Deana on June 11, 2013, 11:19:52 AM
Quote from: stanl on June 11, 2013, 11:10:20 AM
Quote from: td on June 11, 2013, 09:25:01 AM
This is because WinBatch does not support [out] parameters for CLR class methods.

So this is a no-go?
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx (http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx)

What makes you say that? That method doesn't have an output parameter.
Title: Re: WB2013 and Convert Class
Post by: Deana on June 11, 2013, 12:02:05 PM
The Dictionary class TryGetValue Method is an example of a class method with an out parameter: http://msdn.microsoft.com/en-us/library/bb347013.aspx
Title: Re: WB2013 and Convert Class
Post by: ....IFICantBYTE on June 11, 2013, 04:45:48 PM
Stan,
I know you love your .net and powershell stuff (fair enough), but if the end goal in this post is to convert to and from Base64, I have a couple of UDFs somewhere that I can dig up to do that if you want them? .. They call system DLLs and are fast.
If the goal is more about experimenting with the new .net/clr stuff, then no worries.. good luck.. I personally find it a bit confusing and enjoy looking at what you are dabbling with.

Regards,
....IFICantBYTE
Title: Re: WB2013 and Convert Class
Post by: stanl on June 12, 2013, 10:19:45 AM
Quote from: ....IFICantBYTE on June 11, 2013, 04:45:48 PM
If the goal is more about experimenting with the new .net/clr stuff, then no worries.. good luck.. I personally find it a bit confusing and enjoy looking at what you are dabbling with.


Dabbling. Yes. David Gray has an extender that does Base64 and I have an ActiveX and other WB code that can perform it. Want to update my libs to use .NET whenever possible.
Title: Re: WB2013 and Convert Class
Post by: stanl on June 12, 2013, 01:09:46 PM
Quote from: Deana on June 11, 2013, 11:19:52 AM
What makes you say that? That method doesn't have an output parameter.
It was a question and I confused output parm with output. In COM with an ActiveX I can string -> base64 string; but the .NET method appears to output an Array