classic low-level Winapi functions

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

classic low-level Winapi functions

25 Aug 2019, 16:17

I've collected a list of classic low-level Winapi functions.
Please post any further suggestions. Thanks.

CLASSIC FUNCTIONS: BINARY DATA / BYTES / BITWISE

- string length (find first null char): msvcrt\strlen and msvcrt\wcslen [also: msvcrt\strnlen and msvcrt\wcsnlen, kernel32\lstrlen]
- fill bytes with n: kernel32\RtlFillMemory [also: ntdll\RtlFillMemory, msvcrt\memset, msvcrt\_strset]
- fill bytes with 0: kernel32\RtlZeroMemory [also: ntdll\RtlZeroMemory]
- fill shorts with n: msvcrt\_wcsset
- bytes to shorts: kernel32\MultiByteToWideChar [use code page 28591 for an exact conversion]
- shorts to bytes: kernel32\WideCharToMultiByte [use code page 28591 for an exact conversion]
- compare data (indicate if first item is greater/equal/smaller): msvcrt\memcmp
- compare data (get offset of first difference): ntdll\RtlCompareMemory
- copy data: msvcrt\memmove [also: kernel32\RtlMoveMemory]
- byte swap (UShort): msvcr100\_byteswap_ushort
- byte swap (UInt): msvcr100\_byteswap_ulong
- byte swap (UInt64): msvcr100\_byteswap_uint64
- find in data: ??? [see 'FIND IN DATA WORKAROUND', which uses: msvcrt\strlen, ntdll\RtlFillMemory, msvcrt\strstr, msvcrt\memcmp]
- reverse bytes in shorts (in each short, reverse the bytes): msvcrt\_swab

CLASSIC FUNCTIONS: MATHS
- generate random numbers: msvcrt\rand_s, ntdll\RtlRandomEx

CLASSIC FUNCTIONS: STRINGS

- reverse string: msvcrt\_strrev and msvcrt\_wcsrev
- compare file names (like Explorer): shlwapi\StrCmpLogicalW
- find in string: msvcrt\strstr, and msvcrt\wcsstr
- read to ini files: kernel32\GetPrivateProfileString
- write to ini files: kernel32\WritePrivateProfileString
- string compare (case sensitive) (indicate if first item is greater/equal/smaller): kernel32\lstrcmp [also: msvcrt\strcmp and msvcrt\wcscmp, msvcrt\memcmp]
- string compare (case insensitive) (indicate if first item is greater/equal/smaller): kernel32\lstrcmpi [also: msvcrt\_stricmp and msvcrt\_wcsicmp]
- string compare (case sensitive) (get offset of first difference): ntdll\RtlCompareMemory
- string compare (case insensitive) (get offset of first difference): [see 'COMPARE STRINGS CASE INSENSITIVE GET POSITION WORKAROUND', which uses: msvcrt\_wcsnicmp, msvcrt\_strnicmp, msvcrt\memmove, user32\CharLowerBuff, user32\CharUpperBuff, ntdll\RtlCompareMemory]
- to upper case (specify length): user32\CharUpperBuff
- to lower case (specify length): user32\CharLowerBuff
- to upper case (null-terminated string): user32\CharUpper
- to lower case (null-terminated string): user32\CharLower
- to upper case (char number): msvcrt\toupper and msvcrt\towupper
- to lower case (char number): msvcrt\tolower and msvcrt\towlower

CLASSIC FUNCTIONS: CHARACTER CLASSIFICATION

- if char is alnum: user32\IsCharAlphaNumeric [or: msvcrt\isalnum and msvcrt\iswalnum]
- if char is alpha: user32\IsCharAlpha, kernel32\GetStringType [or: msvcrt\isalpha and msvcrt\iswalpha]
- if char is digit: kernel32\GetStringType [or: msvcrt\isdigit and msvcrt\iswdigit]
- if char is lower: user32\IsCharLower, kernel32\GetStringType [or: msvcrt\islower and msvcrt\iswlower]
- if char is space (whitespace): kernel32\GetStringType [or: msvcrt\isspace and msvcrt\iswspace]
- if char is upper: user32\IsCharUpper, kernel32\GetStringType [or: msvcrt\isupper and msvcrt\iswupper]
- if char is xdigit: kernel32\GetStringType [or: msvcrt\isxdigit and msvcrt\iswxdigit]

CLASSIC FUNCTIONS: TEXT ENCODINGS

- encodings to UTF-16 LE: kernel32\MultiByteToWideChar
- UTF-16 LE to encodings: kernel32\WideCharToMultiByte
- UTF-16 LE to/from UTF-16 BE: kernel32\LCMapStringW [use LCMAP_BYTEREV := 0x800]
- get local code page: kernel32\GetACP [also: kernel32\GetOEMCP]

CLASSIC FUNCTIONS: FURTHER

- encode binary data to base64/hex string: crypt32\CryptBinaryToString
- decode base64/hex string to binary data: crypt32\CryptStringToBinary
- get hash (CRC-32): ntdll\RtlComputeCrc32
- get hash (general): bcrypt\BCryptHashData [and other related functions]
- get MessageBox strings: user32\MB_GetString

FIND IN DATA WORKAROUND

find in data workaround (if needle doesn't contain nulls):
- create a copy of the haystack
- repeated msvcrt\strlen and ntdll\RtlFillMemory to remove nulls from the haystack
- msvcrt\strstr to find needle

find in data workaround (if needle does contain nulls):
- create copies of the needle and the haystack
- repeated msvcrt\strlen and ntdll\RtlFillMemory to remove nulls from the needle and the haystack
- msvcrt\strstr to find needle
- compare original needle against original haystack with msvcrt\memcmp (to confirm/disconfirm match)

using RegExMatch:
- AutoHotkey's RegExMatch function can handle binary data.
- It searches for ANSI characters (bytes) in ANSI versions of AutoHotkey.
- It searches for Unicode characters (shorts) in Unicode versions of AutoHotkey.
- To search binary data in Unicode versions, you can do 'bytes to shorts' via kernel32\MultiByteToWideChar (and perhaps code page 28591).

COMPARE STRINGS CASE INSENSITIVE GET POSITION WORKAROUND

compare two strings, case-insensitive, and find the position where the 2 strings differ:
use msvcrt\_wcsnicmp or msvcrt\_strnicmp to compare blocks of characters, find the first 2 blocks that differ
use msvcrt\memmove to create copies of the 2 blocks that differ (create 2 substrings)
use user32\CharLowerBuff to make them lower case (or user32\CharUpperBuff to make them upper case)
use ntdll\RtlCompareMemory to compare the substrings, find the first difference (its offset in bytes)

JavaScript vs AutoHotKey (Simple Speed Test) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=61602&p=297807#p297807

FUNCTIONS LISTED ABOVE

Code: Select all

bcrypt\BCryptHashData
crypt32\CryptBinaryToString
crypt32\CryptStringToBinary
kernel32\GetACP
kernel32\GetOEMCP
kernel32\GetPrivateProfileString
kernel32\GetStringType
kernel32\LCMapStringW
kernel32\lstrcmp
kernel32\lstrcmpi
kernel32\lstrlen
kernel32\MultiByteToWideChar
kernel32\RtlFillMemory
kernel32\RtlMoveMemory
kernel32\RtlZeroMemory
kernel32\WideCharToMultiByte
kernel32\WritePrivateProfileString
msvcr100\_byteswap_uint64
msvcr100\_byteswap_ulong
msvcr100\_byteswap_ushort
msvcrt\_stricmp
msvcrt\_strnicmp
msvcrt\_strrev
msvcrt\_strset
msvcrt\_swab
msvcrt\_wcsicmp
msvcrt\_wcsnicmp
msvcrt\_wcsrev
msvcrt\_wcsset
msvcrt\isalnum
msvcrt\isalpha
msvcrt\isdigit
msvcrt\islower
msvcrt\isspace
msvcrt\isupper
msvcrt\iswalnum
msvcrt\iswalpha
msvcrt\iswdigit
msvcrt\iswlower
msvcrt\iswspace
msvcrt\iswupper
msvcrt\iswxdigit
msvcrt\isxdigit
msvcrt\memcmp
msvcrt\memmove
msvcrt\memset
msvcrt\rand_s
msvcrt\strcmp
msvcrt\strlen
msvcrt\strnlen
msvcrt\strstr
msvcrt\wcscmp
msvcrt\wcslen
msvcrt\wcsnlen
msvcrt\wcsstr
ntdll\RtlCompareMemory
ntdll\RtlComputeCrc32
ntdll\RtlFillMemory
ntdll\RtlRandomEx
ntdll\RtlZeroMemory
shlwapi\StrCmpLogicalW
user32\CharLowerBuff
user32\CharUpperBuff
user32\IsCharAlpha
user32\IsCharAlphaNumeric
user32\IsCharLower
user32\IsCharUpper
user32\MB_GetString
SOME INTERESTING MSVCRT FUNCTIONS

[multiple character needles, first match][returns pointer]
strpbrk - C++ Reference
http://www.cplusplus.com/reference/cstring/strpbrk/
Returns a pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if there are no matches.

[multiple character needles, first match][returns length]
strcspn - C++ Reference
http://www.cplusplus.com/reference/cstring/strcspn/
The length of the initial part of str1 not containing any of the characters that are part of str2.

[multiple character needles, first non-match][returns length]
strspn - C++ Reference
http://www.cplusplus.com/reference/cstring/strspn/
Returns the length of the initial portion of str1 which consists only of characters that are part of str2.

KEY FUNCTIONS *NOT* IN MSVCRT.DLL

The following functions were not in msvcrt.dll, or any of the common Windows dlls that I searched:
wmemchr
wmemcmp [although wcscmp is available]
wmemmove [although memmove is available]
wmemset [although _wcsset is available]

NTDLL.DLL: BYTE SWAP FUNCTIONS (32-BIT ONLY)

The ntdll.dll byte swap functions are in the 32-bit version of the dll only.
ntdll\RtlUshortByteSwap
ntdll\RtlUlongByteSwap
ntdll\RtlUlonglongByteSwap

Alternative functions with 64-bit and 32-bit versions:
msvcr100\_byteswap_ushort
msvcr100\_byteswap_ulong
msvcr100\_byteswap_uint64

LIST THE FUNCTIONS IN A DLL

To list the functions in a dll file, e.g. msvcrt.dll:
LoadPicture() from variable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39002&p=181321#p181321

KEY FUNCTIONS IN BOTH MSVCRT.DLL AND NTDLL.DLL

Code: Select all

;a list of functions that are present in both msvcrt.dll (32-bit and 64-bit) and ntdll.dll (32-bit and 64-bit)

;INTRO

;160 functions

;note: some other functions in msvcrt but not in ntdll:
;atan2 - mathematics (trigonometry)
;_strrev/_wcsrev - reverse string
;_swab - reverse bytes in shorts (in each short, reverse the bytes)

;note: letters in functions:
;atoi ('a' stands for ASCII not ANSI)
;c (a function with special character handling)
;n (limits the search to n bytes/shorts)
;r (reverse, find last occurrence)
;v (a function with special variable handling)
;str/wcs (ANSI string/UTF-16 LE string)

;note: sizes (bytes):
;1 (U)Char, Byte [characters in ANSI strings]
;2 (U)Short [characters in UTF-16 LE strings]
;4 (U)Int, (U)Long
;8 (U)Int64

;FUNCTIONS: PRINT

_snprintf/_snwprintf - print
_snprintf_s/_snwprintf_s - print
_swprintf - print
_vscwprintf - print (from variables) (return character count)
_vsnprintf/_vsnwprintf - print (from variables)
_vsnprintf_s/_vsnwprintf_s - print (from variables)
_vswprintf - print (from variables)
sprintf/swprintf - print
sprintf_s/swprintf_s - print
vsprintf - print (from variables)
vsprintf_s/vswprintf_s - print (from variables)

;FUNCTIONS: CHARACTER TYPES

__isascii - char type
__iscsym - char type (letter/underscore/digit)
__iscsymf - char type (letter/underscore)
__toascii - char type (clear high-order bits)
isalnum - char type
isalpha/iswalpha - char type
iscntrl - char type
isdigit/iswdigit - char type
isgraph - char type
islower/iswlower - char type
isprint - char type
ispunct - char type
isspace/iswspace - char type
isupper - char type [note: iswupper is not in ntdll.dll]
iswctype - char type
isxdigit/iswxdigit - char type
tolower/towlower - string case
toupper/towupper - string case

;FUNCTIONS: CONVERT TYPES

_atoi64 - ANSI string to Int64
_i64toa - Int64 to ANSI string
_i64toa_s - Int64 to ANSI string
_i64tow - Int64 to UTF-16 LE string
_i64tow_s - Int64 to UTF-16 LE string
_itoa - Int to ANSI string
_itoa_s - Int to ANSI string
_itow - Int to UTF-16 LE string
_itow_s - Int to UTF-16 LE string
_ltoa - Long to ANSI string
_ltoa_s - Long to ANSI string
_ltow - Long to ANSI string
_ltow_s - Long to ANSI string
_ui64toa - UInt64 to ANSI string
_ui64toa_s - UInt64 to ANSI string
_ui64tow - UInt64 to UTF-16 LE string
_ui64tow_s - UInt64 to UTF-16 LE string
_ultoa - ULong to ANSI string
_ultoa_s - ULong to ANSI string
_ultow - ULong to UTF-16 LE string
_ultow_s - ULong to UTF-16 LE string
_wcstoui64 - UTF-16 LE string to UInt64
_wtoi - UTF-16 LE string to Int
_wtoi64 - UTF-16 LE string to Int64
_wtol - UTF-16 LE string to Long
atoi - ANSI string to Int
atol - ANSI string to Long
mbstowcs - multibyte character string to UTF-16 LE string
strtol/wcstol - ANSI/UTF-16 LE string to Long
strtoul/wcstoul - ANSI/UTF-16 LE string to ULong
wcstombs - UTF-16 LE string to multibyte character string

;FUNCTIONS: MATHEMATICS

abs - mathematics (abs)
atan - mathematics (trigonometry)
ceil - mathematics (ceil/floor)
cos - mathematics (trigonometry)
fabs - mathematics (abs)
floor - mathematics (ceil/floor)
labs - mathematics (abs)
log - mathematics (powers) (ln)
pow - mathematics (powers)
sin - mathematics (trigonometry)
sqrt - mathematics (powers)
tan - mathematics (trigonometry)

;FUNCTIONS: OTHER

_lfind - find n-byte struct (based on comparison function) (doesn't require array to be sorted)
_makepath_s/_wmakepath_s - join string
_memccpy - copy/move (like memcpy, but stops if a particular character is seen)
_memicmp - compare (case insensitive)
_snscanf_s/_snwscanf_s - string split to variables
_splitpath - split string
_splitpath_s/_wsplitpath_s - split string
_strcmpi - compare (case insensitive) (use _stricmp instead)
_stricmp/_wcsicmp - compare (case insensitive)
_strlwr/_wcslwr - string case
_strnicmp/_wcsnicmp - compare (case insensitive)
_strnset_s/_wcsnset_s - write
_strset_s/_wcsset_s - write
_strupr/_wcsupr - string case
bsearch - find n-byte struct (based on comparison function) (requires array to be sorted)
memchr - find char (doesn't stop at null bytes) (cf. strlen/wcslen that do stop at null bytes/shorts)
memcmp - compare
memcpy - copy/move
memcpy_s - copy/move
memmove - copy/move
memmove_s - copy/move
memset - write
qsort - sort n-byte structs (based on comparison function)
sscanf - string split to variables
sscanf_s/swscanf_s - string split to variables
strcat/wcscat - concatenate
strcat_s/wcscat_s - concatenate
strchr/wcschr - find byte/short
strcmp/wcscmp - compare
strcpy/wcscpy - copy/move
strcpy_s/wcscpy_s - copy/move
strcspn/wcscspn - find first character that is one of the needle characters (cf. strspn/wcsspn)
strlen/wcslen - find null byte/short (length)
strncat/wcsncat - concatenate
strncat_s/wcsncat_s - concatenate
strncmp/wcsncmp - compare
strncpy/wcsncpy - copy
strncpy_s/wcsncpy_s - copy
strnlen/wcsnlen - find null byte/short (length)
strpbrk/wcspbrk - find first character that is one of the needle characters (like strcspn/wcscspn, but returns a pointer)
strrchr/wcsrchr - find byte/short (reverse)
strspn/wcsspn - find first character that isn't one of the needle characters (cf. strcspn/wcscspn)
strstr/wcsstr - find string
strtok_s - parse a string based on delimiters (get tokens)
KEY STRXXX FUNCTIONS IN EITHER SHELL32.DLL OR SHLWAPI.DLL

Code: Select all

;a list of StrXXX functions that are present in either shell32.dll or shlwapi.dll

;unique to shell32:
StrNCmpA
StrNCmpIA
StrNCmpIW
StrNCmpW
StrRStrA
StrRStrW

;unique to shlwapi:
StrCSpnA
StrCSpnIA
StrCSpnIW
StrCSpnW
StrCatBuffA
StrCatBuffW
StrCatChainW
StrCatW
StrChrNIW
StrChrNW
StrCmpCA
StrCmpCW
StrCmpICA
StrCmpICW
StrCmpIW
StrCmpLogicalW
StrCmpNCA
StrCmpNCW
StrCmpNICA
StrCmpNICW
StrCmpW
StrCpyNW
StrCpyW
StrDupA
StrDupW
StrFormatByteSize64A
StrFormatByteSizeA
StrFormatByteSizeEx
StrFormatByteSizeW
StrFormatKBSizeA
StrFormatKBSizeW
StrFromTimeIntervalA
StrFromTimeIntervalW
StrIsIntlEqualA
StrIsIntlEqualW
StrNCatA
StrNCatW
StrPBrkA
StrPBrkW
StrRetToBSTR
StrRetToBufA
StrRetToBufW
StrRetToStrA
StrRetToStrW
StrSpnA
StrSpnW
StrStrNIW
StrStrNW
StrToInt64ExA
StrToInt64ExW
StrToIntA
StrToIntExA
StrToIntExW
StrToIntW
StrTrimA
StrTrimW

;present in both shell32 and shlwapi:
StrChrA
StrChrIA
StrChrIW
StrChrW
StrCmpNA
StrCmpNIA
StrCmpNIW
StrCmpNW
StrRChrA
StrRChrIA
StrRChrIW
StrRChrW
StrRStrIA
StrRStrIW
StrStrA
StrStrIA
StrStrIW
StrStrW
MULDIV TRICK

MulDiv trick seen in some older scripts:

Code: Select all

;MulDiv trick, based on:
;How to get a string from its pointer and length - Ask for Help - AutoHotkey Community
;https://autohotkey.com/board/topic/36052-how-to-get-a-string-from-its-pointer-and-length/

;MulDiv trick:
;return a string, starting at a specified address, ending at a null character
;note: the first of the 3 arguments (nNumber) is passed the address at which to read the string
;note: ... the address must be a 32-bit integer (on 64-bit scripts, addresses might be larger than this)
;note: the DllCall return type must be one of Str/AStr/WStr
VarSetCapacity(vText, 100)
VarSetCapacity(vTextA, 100)
VarSetCapacity(vTextW, 100)
StrPut("abcdefghijklmnopqrstuvwxyz", &vText)
StrPut("abcdefghijklmnopqrstuvwxyz", &vTextA, "CP0")
StrPut("abcdefghijklmnopqrstuvwxyz", &vTextW, "UTF-16")
vAddr := &vText + (A_IsUnicode?2:1)*10
vAddrA := &vTextA + 10
vAddrW := &vTextW + 20
MsgBox, % DllCall("kernel32\MulDiv", "Int",vAddr, "Int",1, "Int",1, "Str")
MsgBox, % DllCall("kernel32\MulDiv", "Int",vAddrA, "Int",1, "Int",1, "AStr")
MsgBox, % DllCall("kernel32\MulDiv", "Int",vAddrW, "Int",1, "Int",1, "WStr")
return
LINKS

Win32 Equivalents for C Run-Time Functions
https://support.microsoft.com/en-us/help/99456/win32-equivalents-for-c-run-time-functions
Buffer manipulation | Microsoft Docs
https://docs.microsoft.com/en-us/cpp/c-runtime-library/buffer-manipulation?view=vs-2019
Microsoft Windows library files - Wikipedia
https://en.wikipedia.org/wiki/Microsoft_Windows_library_files#MSVCRT.DLL,_MSVCP*.DLL_and_CRTDLL.DLL
c - How does memchr() work under the hood? - Stack Overflow
https://stackoverflow.com/questions/525123/how-does-memchr-work-under-the-hood
MakeXXX macros (MAKEWORD, MAKELONG etc) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=68367
Last edited by jeeswg on 30 Nov 2019, 13:37, edited 10 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4459
Joined: 17 Jul 2016, 01:02
Contact:

Re: classic low-level Winapi functions

26 Aug 2019, 00:26

I wouldn't call anything in msvcrt classic winapi as it is the standard C library.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: classic low-level Winapi functions

07 Sep 2019, 17:09

Well, in that case, think of it as 'classic low-level functions that appear in the Winapi'.

Although, maybe the C functions above are both classic C functions *and* classic Winapi functions.

Btw it's been difficult to find a manageable list of classic C functions that are in the Winapi.
I somehow(!?) came across the fact there is some overlap between msvcrt.dll and ntdll.dll.
And found 160 functions that appear in all four of: msvcrt.dll (32-bit/64-bit) and ntdll.dll (32-bit/64-bit), they are listed above, as a very good starting point.
Any other sources of classic C functions in the Winapi?

In summary:
I found 1227 functions in msvcrt.dll (present in both 32-bit/64-bit versions).
Of those, 160 are also in ntdll.dll (present in both 32-bit/64-bit versions).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Getfree
Posts: 219
Joined: 12 Oct 2014, 18:00

Re: classic low-level Winapi functions

07 Sep 2019, 20:08

Functions in msvcrt.dll are needed for programs compiled by Microsoft's Visual C++ Compiler and other compilers that use Microsoft's C compiler as part of their compilation process.

Programs in a different language (like Pascal/Delphi) or compiled by a different brand of compiler altogether, don't need msvcrt.dll at all.

Also, if a program is compiled statically, they also don't need to use msvcrt.dll whatsoever.

ntdll.dll, on the other hand, is a completely different story. This DLL is fundamental for all Win32 applications, they must absolutely use it.
It's so fundamental, that some functions in msvcrt.dll depend on functions in ntdll.dll.

Learn more at: https://en.wikipedia.org/wiki/Microsoft_Windows_library_files
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: classic low-level Winapi functions

24 Sep 2019, 22:08

I was wondering if there were basic mathematical/bitwise functions in the Winapi.
I did find these, which are applied to VARIANT structs:

[VarXXX functions]
Variant Arithmetic Functions (Automation)
https://msdn.microsoft.com/en-us/ie/ms221430(v=vs.100)
[VT_XXX types]
ComObjType() - Syntax & Usage | AutoHotkey
https://www.autohotkey.com/docs/commands/ComObjType.htm

Any others? Thanks.

Code: Select all

;q:: ;VarXXX functions in oleaut32
VarSetCapacity(VARIANT1, A_PtrSize=8?24:16, 0)
VarSetCapacity(VARIANT2, A_PtrSize=8?24:16, 0)
VarSetCapacity(VARIANT3, A_PtrSize=8?24:16, 0)

;3 * 4 = 12
;VT_I8 := 0x14 ;64-bit signed int
NumPut(0x14, &VARIANT1, 0, "UShort")
NumPut(3, &VARIANT1, 8, "Int64")
NumPut(0x14, &VARIANT2, 0, "UShort")
NumPut(4, &VARIANT2, 8, "Int64")
DllCall("oleaut32\VarMul", "Ptr",&VARIANT1, "Ptr",&VARIANT2, "Ptr",&VARIANT3)
MsgBox, % NumGet(&VARIANT3, 8, "Int64")

;3.5 * 4 = 14
;VT_R8 := 0x5 ;64-bit floating-point number
NumPut(0x5, &VARIANT1, 0, "UShort")
NumPut(3.5, &VARIANT1, 8, "Double")
NumPut(0x5, &VARIANT2, 0, "UShort")
NumPut(4, &VARIANT2, 8, "Double")
DllCall("oleaut32\VarMul", "Ptr",&VARIANT1, "Ptr",&VARIANT2, "Ptr",&VARIANT3)
MsgBox, % NumGet(&VARIANT3, 8, "Double")
return
There's also the MulDiv function:

Code: Select all

;q:: ;test multiply/divide
MsgBox, % MyMul(10, 3) ;30
MsgBox, % MyMul(-10, 3) ;-30
MsgBox, % MyDiv(10, 3) ;3
MsgBox, % MyDiv(-10, 3) ;-3
return

;multiply integers
MyMul(vNum1, vNum2)
{
	return DllCall("kernel32\MulDiv", "Int",vNum1, "Int",vNum2, "Int",1)
}

;divide integers (and round)
MyDiv(vNum1, vNum2)
{
	return DllCall("kernel32\MulDiv", "Int",vNum1, "Int",1, "Int",vNum2)
}
@Getfree: Thanks for the info.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests