WinAPI使うのもいいかもしれませんね。
#include "hsp3utf.as"
#define global WSTR_USEMACLANG //機械語を使うかどうか
; wstr.as
#ifndef WSTR_AS
#define WSTR_AS
#ifdef WSTR_USEMACLANG
; xalloc.as
#ifndef XALLOC_AS
#define XALLOC_AS
#module
#uselib "kernel32.dll"
#func VirtualProtect "VirtualProtect" var, int, int, var
#define global PAGE_EXECUTE_READWRITE 0x00000040
#deffunc xalloc var mem, int size
dim mem, size / 4 + 1
temp = 0
VirtualProtect mem, size, PAGE_EXECUTE_READWRITE, temp
return
#global
#endif
#endif
#module
#uselib "kernel32.dll"
#cfunc lstrlen "lstrlenW" wstr
#func lstrcpyn "lstrcpynW" int, int, int
#uselib "user32.dll"
#cfunc CharNext "CharNextW" int
#ifdef WSTR_USEMACLANG
#deffunc wstr_init
xalloc wstrmid_f_, 48
wstrmid_f_(0) = $0824448b,$24748b56,$7ef68510,$11bf570f
wstrmid_f_(4) = $50111111,$ee83d7ff,$5ff87501,$14244c8b
wstrmid_f_(8) = $ff505141,$b8102474,$22222222,$c35ed0ff
lpoke wstrmid_f_, 15, varptr(CharNext)
lpoke wstrmid_f_, 40, varptr(lstrcpyn)
return
#endif
#defcfunc wstrmid str _src, int _index, int _len
size = strlen(_src) * 2
sdim src, size
sdim dest, size
cnvstow src, _src
#ifdef WSTR_USEMACLANG
prm = varptr(dest), varptr(src), _index, _len
res = callfunc(prm, varptr(wstrmid_f_), 4)
#else
p = varptr(src)
repeat _index
p = CharNext(p)
loop
lstrcpyn varptr(dest), p, _len + 1
#endif
dest = cnvwtos(dest)
return dest
#defcfunc wstrlen str _s
return lstrlen(_s)
#global
#ifdef WSTR_USEMACLANG
wstr_init
#endif
#endif
buf = "指定した TCHAR の数の文字を格納"
mes wstrlen(buf) ; => 19
mes wstrmid(buf, 5, 8) ; => "TCHARの数"
; wstrmid.c
/*
void wstrmid(int dest, int src, int index, int len)
{
typedef int (__stdcall *next_t)(int);
typedef int (__stdcall *copyn_t)(int, int, int);
next_t next = (next_t)0x11111111;
copyn_t copyn = (copyn_t)0x22222222;
int p = src;
for (int i = 0; i < index; i++)
p = next(p);
copyn(dest, p, len + 1);
}
*/