ComMÉDIA
for Windows CE HomeArticlesUDT's (II) ActiveX Controls



References


Windows CE
Web Community



[Prev] [Random] [Next]
[List Sites] [Next 5]

Passing UDT's (User Defined Types) on API calls with VBCE

(Download Code)  

Part 2

UDT’s on Windows CE:

We may assume that the same approach was used on Windows CE. However, this hasn’t been tested systematically on all the processors supported by Windows CE . Take caution with this.

So, now that we know how to fill every byte of a UDT, all we have to do is write some functions to build a String with the exact same values. For our example:

Public Function IntegerToBinaryString(ByVal IntIn As Integer) As String
Dim aux As Integer
aux = IntIn: If IntIn < 0 Then aux = IntIn - &H8000
IntegerToBinaryString = _
IntegerToBinaryString & ChrB(aux Mod 256)
aux = aux \ 256
If IntIn < 0 Then
IntegerToBinaryString = _
IntegerToBinaryString & ChrB(aux + &H80)
Else
IntegerToBinaryString = _
IntegerToBinaryString & ChrB(aux)
End If
End Function

Public Function SYSTEMTIME( _
wYear As Integer, _
wMonth As Integer, _
wDayOfWeek As Integer, _
wDay As Integer, _
wHour As Integer, _
wMinute As Integer, _
wSecond As Integer, _
wMilliseconds As Integer) As String

SYSTEMTIME = _
IntegerToBinaryString(wYear) & _
IntegerToBinaryString(wMonth) & _
IntegerToBinaryString(wDayOfWeek) & _
IntegerToBinaryString(wDay) & _
IntegerToBinaryString(wHour) & _
IntegerToBinaryString(wMinute) & _
IntegerToBinaryString(wSecond) & _
IntegerToBinaryString(wMilliseconds)

End Function

Be careful with the Declare statement: the UDT must always be specified as a String passed ByVal which IS NOT what you’ll find on the "API Text Viewer " for the Winceapi. This is the correct Declare:

Declare Function SetLocalTime Lib "Coredll" _
(ByVal lpSystemTime As String) As Long

Notice that, on Windows CE, most of the system calls will use "Coredll.dll" instead of "Kernel32.dll". Also, Windows CE is a UNICODE OS meaning that every string character occupies two bytes. Be careful: for example, Mid(StringIn, 1, 1) will return two bytes; MidB(StringIn, 1, 1) will return only one.

Our call ends up as follows:

Dim sysTime as string

and will perform the same way as its 95/98/NT counterpart.

There are still other problems that we could face: when we have a UDT with a UDT field. This would mean that we’d have to pass the address of the inner UDT as a Long in the outer UDT. However, these functions are seldom used.

Other problem, which is much more common, is when we pass na empty UDT to the system call in order to receive the information back from that call inside this UDT.

Let’s assume we implement the code to have a calendar control on our form. This is more complicated because will have to deal with messages between windows. However, the interesting part for our discussion is that the Time/Date is sent back to us as a SYSTEMTIME UDT.

As we saw previously, we have to reserve an empty block of memory with the same size as the UDT. In VBCE there’s no fixed length strings (we can’t use Dim aux * 8 , p.e) but this is easily solved:

Dim aux as String: aux = String(8, Chr(0))

Remember that WinCE uses UNICODE: we’ve just reserverd 16 bytes of memory - the same size as a SYSTEMTIME UDT variable.

Call the function as in the following example:

MonthCal_GetCurSel = SendMessage(hmc, MCM_GETCURSEL, 0, aux)

In "aux" we receive a string with all the UDT bytes. Let’s get them:

Dim wYear As Integer, wMonth As Integer, wDayOfWeek As Integer
Dim wDay As Integer, wHour As Integer, wMinute As Integer
Dim wSecond As Integer, wMilliseconds As Integer
Call getSYSTEMTIME(aux, _
wYear, wMonth, wDayOfWeek, wDay, wHour, _
wMinute, wSecond, wMilliseconds)

And the last thing: implement the "get" functions:

Public Function BinaryStringToInteger(StringIn As String) As Integer
If AscB(MidB(StringIn, 2)) And &H80 Then
BinaryStringToInteger = _
(AscB(MidB(StringIn, 2)) - &HFF) * 256 + _
(AscB(StringIn) - 256)
 Else
BinaryStringToInteger = _
AscB(MidB(StringIn, 2)) * 256 + AscB(StringIn)
End If
End Function

Public Sub getSYSTEMTIME(ByVal str As String, _
ByRef wYear As Integer, ByRef wMonth As Integer, _
ByRef wDayOfWeek As Integer, ByRef wDay As Integer, _
ByRef wHour As Integer, ByRef wMinute As Integer, _
ByRef wSecond As Integer, ByRef wMilliseconds As Integer)

wYear = BinaryStringToInteger(MidB(str, 1, 2)))
wMonth = BinaryStringToInteger(MidB(str, 3, 2))
wDayOfWeek = BinaryStringToInteger(MidB(str, 5, 2))
wDay = BinaryStringToInteger(MidB(str, 7, 2))
wHour = BinaryStringToInteger(MidB(str, 9, 2))
wMinute = BinaryStringToInteger(MidB(str, 11, 2))
wSecond = BinaryStringToInteger(MidB(str, 13, 2))
wMilliseconds = BinaryStringToInteger(MidB(str, 15, 2))

End Sub

Written on: 12/Oct/99
By: Antonio Paneiro
ComMEDIA,Lda.
apaneiro@commedia.pt
http://www.commedia.pt/ce



[ Home ] [ Source Code ] [ Articles ] [ Download ] [ Support ]
[ VBCE Icons Tool ] [ ActiveX Controls ]

Copyright ComMedia 2000-2003. All rights reserved.
Microsoft, Windows CE, and Visual Basic are registered trademarks of Microsoft Corporation.

Windows CE ActiveX Controls specifically designed in ATL for eVB.

Date Time
Month Calendar
Progress Bar
Popup Menu
Tray Icon
Locale
Settings
RAS Dial
RAS Entries
RAS PPTP

>> Try them! <<


Icons Tool

The Evaluation version of the
VBCE Icons Tool
performs exactly as the registered version but draws all Icons over a grid with scrambled colors .

Check the details.

VBCE UDT's

"...to extend the intrinsic VB functionality with extra functions provided by the MS Windows Operating System..."

more...