/
ResStr.prg
90 lines (52 loc) · 1.63 KB
/
ResStr.prg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// <include file="Gui.xml" path="doc/ResourceString/*" />
CLASS ResourceString INHERIT VObject
PROTECT iLength AS INT
PROTECT sBuffer AS STRING
/// <include file="Gui.xml" path="doc/ResourceString.AsString/*" />
METHOD AsString()
RETURN sBuffer
/// <include file="Gui.xml" path="doc/ResourceString.ctor/*" />
CONSTRUCTOR(xResourceID, nMaxLen)
LOCAL hInst AS PTR
LOCAL wID AS DWORD
LOCAL ptrBuffer AS PTR
SUPER()
IF IsNumeric(xResourceID) .OR. IsSymbol(xResourceID)
xResourceID := ResourceID{xResourceID} // , GetNatDLLHandle()}
ELSEIF !(xResourceID IS ResourceID)
WCError{#Init, #ResourceString, __WCSTypeError, xResourceID, 1}:Throw()
ENDIF
IF IsNil(nMaxLen)
nMaxLen := 256
ELSEIF !IsNumeric(nMaxLen)
WCError{#Init, #ResourceString, __WCSTypeError, nMaxLen, 2}:Throw()
ENDIF
hInst := xResourceID:Handle()
IF IsString(xResourceID:ID)
wID := DWORD(_CAST, String2Symbol(xResourceID:ID))
ELSE
wID := xResourceID:ID
ENDIF
#ifdef __VULCAN__
// If this is used to load a string from something other than
// the nations DLL, use LoadString(). Otherwise, try to
// load the string from the Vulcan runtime managed resources.
IF hInst == GetNatDllHandle()
sBuffer := __CavoStr( wID )
RETURN
ENDIF
#endif
ptrBuffer := MemAlloc(nMaxLen)
iLength := LoadString(hInst, wID, ptrBuffer, nMaxLen)
IF iLength != 0
sBuffer := Psz2String(ptrBuffer)
ENDIF
MemFree(ptrBuffer)
RETURN
/// <include file="Gui.xml" path="doc/ResourceString.Length/*" />
ACCESS Length
RETURN iLength
/// <include file="Gui.xml" path="doc/ResourceString.Value/*" />
ACCESS Value
RETURN sBuffer
END CLASS