LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Why does timeGetDevCaps fail?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does hyperlink fail? Terry Pinnell[_2_] Excel Discussion (Misc queries) 4 December 7th 11 06:50 PM
Templates Fail Brian Excel Discussion (Misc queries) 0 November 15th 06 07:18 PM
why does this fail? Gixxer_J_97[_2_] Excel Programming 5 May 18th 05 12:49 PM
pass fail Tricia New Users to Excel 3 January 20th 05 03:45 PM
Fail if macros are not enabled? JonF Excel Programming 1 October 23rd 03 05:10 PM


All times are GMT +1. The time now is 09:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"