Forum > Windows
activex.pp DosDateTimeToVariantTime definition problem
440bx:
Hello,
in activex.pp, DosDateTimeToVariantTime is defined as:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function DosDateTimeToVariantTime( wDosDate: ushort; wDosTime:ushort;pvtime:pdouble):longint; stdcall; external oleaut32dll name 'DosDateTimeToVariantTime'; Note the result type of "longint". This result type is incorrect.
The documentation page:
https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-dosdatetimetovarianttime
shows the function definition to be:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---INT DosDateTimeToVariantTime( [in] USHORT wDosDate, [in] USHORT wDosTime, [out] DOUBLE *pvtime); which is also incorrect.
The same page describes the return value:
--- Quote ---The function returns TRUE on success and FALSE otherwise.
--- End quote ---
That's a BOOL (or possibly boolean), not an INT.
To determine which one is correct, inspection of the function's dis-assembly (partial) shows the following:
--- Code: ASM [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---.text:100169DF call _ErrPackDate@20 ; ErrPackDate(x,x,x,x,x).text:100169E4 test eax, eax.text:100169E6 jnz short loc_100169FF.text:100169E8 fld [ebp+var_24].text:100169EB inc eax.text:100169EC fstp qword ptr [ebx].text:100169EE.text:100169EE loc_100169EE: ; CODE XREF: DosDateTimeToVariantTime(x,x,x)+D1↓j.text:100169EE mov ecx, [ebp+var_4].text:100169F1 pop edi.text:100169F2 pop esi.text:100169F3 xor ecx, ebp ; StackCookie.text:100169F5 pop ebx.text:100169F6 call @__security_check_cookie@4 ; __security_check_cookie(x).text:100169FB leave.text:100169FC retn 0Ch.text:100169FF ; ---------------------------------------------------------------------------.text:100169FF.text:100169FF loc_100169FF: ; CODE XREF: DosDateTimeToVariantTime(x,x,x)+74↑j.text:100169FF ; DosDateTimeToVariantTime(x,x,x)+84↑j ....text:100169FF xor eax, eax.text:10016A01 jmp short loc_100169EE.text:10016A01 _DosDateTimeToVariantTime@12 endp.text:10016A01 The dis-assembly clearly shows that the function returns 1 when successful and 0 upon failure, this fits a BOOL.
As currently defined, there is room for the result to be misinterpreted depending on how the comparison is done against the "supposed int".
HTH.
Thaddy:
This stems (both issues) from C(++) compilers interpreting false as zero and anything else a valid true.
Predates compilers with _Bool. As such it was correct at the time as BOOL (Uppercase and without underscore) was a type macro over longint.
ASerge:
--- Quote from: 440bx on July 13, 2025, 11:54:32 am ---The documentation page: ...
...which is also incorrect.
--- End quote ---
This is the official documentation, so we need to rely on it, despite the current implementation.
And it's not that hard, instead
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if DosDateTimeToVariantTime(...) thenwrite it as
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if DosDateTimeToVariantTime(...) <> 0 then
440bx:
Official or otherwise, it's incorrect.
A longint does not have the semantic properties of a boolean.
In addition to that, the documentation contradicts itself. In one place it shows the return value as being an int and then it states it is a boolean.
Look at the code to figure out which one is right and boolean is right, int is incorrect and leaves room for an improper comparison that would yield incorrect results.
PascalDragon:
--- Quote from: 440bx on July 13, 2025, 11:54:32 am ---The documentation page:
https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-dosdatetimetovarianttime
shows the function definition to be:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---INT DosDateTimeToVariantTime( [in] USHORT wDosDate, [in] USHORT wDosTime, [out] DOUBLE *pvtime); which is also incorrect.
--- End quote ---
The actual header OleAuto.h (not the documentation) nevertheless declares it as INT, not as BOOL. It doesn't matter whether the return values are provided using the TRUE and FALSE macros inside DosDateTimeToVariantTime (and its inverse), the decaration is nevertheless INT.
Yes, that could be misinterpreted, but one is supposed to use MSDN when working with the Windows API anyway.
Navigation
[0] Message Index
[#] Next page