Monday, December 19, 2011

[Lhogho] IsInetOffline? an example of Win32 API wrapping.

Lately I've been having a lot of fun getting my head around the Lhogho programming language. It's a compiled variant of Logo, running on Linux and Windows.

The following code demonstrates wrapping the Win32 API, in this case the IsInetOffline function in URL.DLL. The commented line is taken from a WIN32API.TXT file I found on the internet.

; Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwflags As Long) As Long
make "url_handle libload "url.dll
to InetIsOffline? :dwflags end
external "InetIsOffline? [ U4 InetIsOffline U4] :url_handle

ifelse InetIsOffline? 0 <> 0
 [ print [internet offline] ]
 [ print [internet online] ]

I rather like the notation for defining the call to the DLL itself:
'external' <localsymbol> '[' <returntype> <dllsymbol> <arg1type> ... ']' <libloadvalue>

I've written a few bits and pieces of code which can be found over on the Lhogho forum. Enjoy!

Monday, January 03, 2011

[VB6] Using VBScript's Escape and UnEscape (Take 2)

It's been pointed out to me recently that Escape() doesn't handle embedded quotes and embedded newlines. This is the fix.

I'm using JScript rather than VBScript, so that I can use the String object's fromCharCode() method. I parse the input string, convert the characters to a list of their numeric equivalents for passing to fromCharCode() and then store the result in a JScript variable which is then passed to escape().

Thanks to Anonymous and anjali kalkarni for pointing out the problem.

© Bruce M. Axtens, 2011