Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why does timeGetDevCaps fail in the VBA sub below?
And when it fails, why does it return TIMERR_NOCANDO instead of TIMERR_STATUS? (Or so it seems.) (I suspect the latter is simply a defect either in the documentation or in the library implementation. Other related functions do return TIMERR_NOCANDO.) According to "man pages" and header files that I found in Google searches, timeGetDevCaps and related identifiers are defined as follows. MMRESULT timeGetDevCaps( LPTIMECAPS ptc, UINT cbtc ) Parameters: ptc: Pointer to a TIMECAPS structure. cbtc: Size, in bytes, of the TIMECAPS structure. Return Values Returns TIMERR_NOERROR if successful or TIMERR_STRUCT if it fails to return the timer device capabilities. Requirements and Library: Same as timeGetTime et al, which seem to work just fine. Related declarations: alias UINT MMRESULT struct TIMECAPS { UINT wPeriodMin; UINT wPeriodMax; } alias TIMECAPS* PTIMECAPS, LPTIMECAPS const TIMERR_BASE=96 const TIMERR_NOERROR=0 const TIMERR_NOCANDO=(TIMERR_BASE+1) // 97 const TIMERR_STRUCT=(TIMERR_BASE+33) // 129 Of course, I cannot say for sure whether those related declarations -- especially the TIMERR constant -- apply to my system. But I assume they do. I am using MSWin XP Pro (32-bit), Excel 2003 with VB 6.3. On the off-chance that the DLL integer is different from the VBA integer -- unlikely, I know, but I am used to ILP32 archtectures where int and long (and pointer) are 32-bit -- I tried calling timeGetDevCaps with cbtc set to 8 instead of 4. Not surprisingly, I get run-time error 49 (bad DLL calling convention). My VBA code.... Type TIMECAPS min As Integer max As Integer End Type Public Declare Function timeGetDevCaps Lib "winmm" (ByRef tcaps As TIMECAPS, ByVal sz As Integer) As Integer Public Declare Function timeBeginPeriod Lib "winmm" (ByVal msec As Integer) As Integer Public Declare Function timeEndPeriod Lib "winmm" (ByVal msec As Integer) As Integer Public Declare Function timeGetTime Lib "winmm" () As Long Public Declare Sub Sleep Lib "kernel32" (ByVal msec As Long) Private Sub testWinmm() Dim tc As TIMECAPS Dim x As Integer Dim st As Long, et As Long, dt As Long '*****ERROR: timeGetDevCaps does not return 0 tc.min = -123: tc.max = -456 x = timeGetDevCaps(tc, 4) Debug.Print "timeGetDevCaps="; x; _ " min="; IIf(tc.min = -123, "UNCHANGED ", tc.min); _ " max="; IIf(tc.max = -456, "UNCHANGED", tc.max) 'Everything else works (i.e. does not return error status) x = timeBeginPeriod(1) Debug.Print "timeBeginPeriod="; x x = timeEndPeriod(1) Debug.Print "timeEndPeriod="; x st = timeGetTime() Call Sleep(1000) et = timeGetTime() dt = et - st Debug.Print "st="; st; " et="; et; " dt="; dt End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Why does hyperlink fail? | Excel Discussion (Misc queries) | |||
Templates Fail | Excel Discussion (Misc queries) | |||
why does this fail? | Excel Programming | |||
pass fail | New Users to Excel | |||
Fail if macros are not enabled? | Excel Programming |