WinBatch® Technical Support Forum

Archived Boards => COM Automation and dotNet => Topic started by: stanl on January 24, 2014, 11:54:55 AM

Title: TimeSpan and the CLR
Post by: stanl on January 24, 2014, 11:54:55 AM
This is based on a recent post in the Main forum where a user wanted to set and increment a time variable. Thought I'd take a whack at the CLR TimeSpan... Got an error, so yet another chance to learn

Code (WINBATCH) Select

;trying time span with WB and CLR
t = ObjectClrNew( "System.DateTime")
today = t.Now
Message("",today)


;get error Method Type Signature Not Interop Compatible
;h =  ObjectType("I4",1)
;m =  ObjectType("I4",0)
;s =  ObjectType("I4",0)
;ts = ObjectClrNew( "System.TimeSpan",h,m,s)
;new= today.add(ts)
;Message("",new)

t=0
Exit
Title: Re: TimeSpan and the CLR
Post by: td on January 24, 2014, 01:31:45 PM
The 'more error info' message is poorly worded but it still says it all.  It likely ain't gonna work in WinBatch.  There aren't many of them but some of the 'System' FCL structures don't support being created using the CLR's native early bind COM API.   
Title: Re: TimeSpan and the CLR
Post by: stanl on January 25, 2014, 03:14:59 AM
Quote from: td on January 24, 2014, 01:31:45 PM
The 'more error info' message is poorly worded but it still says it all.  It likely ain't gonna work in WinBatch.  There aren't many of them but some of the 'System' FCL structures don't support being created using the CLR's native early bind COM API.

Does this also apply to Plan-B's: i.e. leveraging through Powershell, or creating a .dll from C# code?
Title: Re: TimeSpan and the CLR
Post by: DAG_P6 on January 25, 2014, 12:14:21 PM
While I cannot answer with respect to PowerShell, I have created a couple of COM DLLs in C#, to enable me to import assembly properties into Microsoft Excel. To be sure, there are plenty of rules, limitations, and traps for the unwary, and the process is poorly documented, but it can be done.

Off the top of my head, two of the most important rules are the following.

Title: Re: TimeSpan and the CLR
Post by: td on January 25, 2014, 11:27:59 PM
Quote from: stanl on January 25, 2014, 03:14:59 AM
Does this also apply to Plan-B's: i.e. leveraging through Powershell, or creating a .dll from C# code?

A simple C# cover assembly compiled using WinBatch would be one possible solution.  However, since the problem can be easy solved in strait WIL without the assistance of the CLR, it appears to be overkill. 
Title: Re: TimeSpan and the CLR
Post by: DAG_P6 on January 27, 2014, 06:00:40 PM
Quote from: td on January 25, 2014, 11:27:59 PM
Quote from: stanl on January 25, 2014, 03:14:59 AM
Does this also apply to Plan-B's: i.e. leveraging through Powershell, or creating a .dll from C# code?

A simple C# cover assembly compiled using WinBatch would be one possible solution.  However, since the problem can be easy solved in strait WIL without the assistance of the CLR, it appears to be overkill.

I agree. Convert to OADate, and do all the maths you want.