Microsoft KB Archive/241530: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - """ to """)
 
(2 intermediate revisions by the same user not shown)
Line 45: Line 45:
== SUMMARY ==
== SUMMARY ==


&quot;Currently there is no explicit support for user-defined data types (UDTs) in either eMbedded Visual Basic 3.0 (eVB) or the Microsoft Windows CE Toolkit for Visual Basic 6.0 (VBCE).<br />
"Currently there is no explicit support for user-defined data types (UDTs) in either eMbedded Visual Basic 3.0 (eVB) or the Microsoft Windows CE Toolkit for Visual Basic 6.0 (VBCE).<br />
<br />
<br />
This article illustrates one approach to calling Windows CE APIs from eVB/VBCE applications that require the use of UDT structures. This method requires use of advanced manipulation techniques for storing this data in memory.
This article illustrates one approach to calling Windows CE APIs from eVB/VBCE applications that require the use of UDT structures. This method requires use of advanced manipulation techniques for storing this data in memory.
Line 61: Line 61:
As a workaround to this limitation, there is a way you can manipulate the data and coax the contents of your would-be UDTs into a String variable that can be passed into an API call in the same format as a UDT would pass them. This example shows how to convert Long Integer data types into a string format compatible with how data is stored in memory.<br />
As a workaround to this limitation, there is a way you can manipulate the data and coax the contents of your would-be UDTs into a String variable that can be passed into an API call in the same format as a UDT would pass them. This example shows how to convert Long Integer data types into a string format compatible with how data is stored in memory.<br />
<br />
<br />
'''NOTE''': Be careful with the Declaration statement in eVB/VBCE. The UDT should '''always''' be specified as a String passed ByVal. This is in contrast to what you find in the &quot;API Text Viewer&quot; viewing the Winceapi.txt file.
'''NOTE''': Be careful with the Declaration statement in eVB/VBCE. The UDT should '''always''' be specified as a String passed ByVal. This is in contrast to what you find in the "API Text Viewer" viewing the Winceapi.txt file.
<ol>
<ol>
<li>Create a new Windows CE project in either Visual Basic or eMbedded Visual Basic. Form1 is created by default.</li>
<li>Create a new Windows CE project in either Visual Basic or eMbedded Visual Basic. Form1 is created by default.</li>
Line 69: Line 69:
'
'
' Note: lpRect is passed as ByVal.
' Note: lpRect is passed as ByVal.
Declare Function GetWindowRect Lib &quot;Coredll&quot; ( _
Declare Function GetWindowRect Lib "Coredll" ( _
     ByVal hwnd As Long, ByVal lpRect As String) As Long
     ByVal hwnd As Long, ByVal lpRect As String) As Long


Line 80: Line 80:
     hWorkVal = Hex(AscB(MidB(StringIn, 2, 1)))
     hWorkVal = Hex(AscB(MidB(StringIn, 2, 1)))
     If Not Err Then
     If Not Err Then
         hWorkVal = hWorkVal &amp; Hex(AscB(MidB(StringIn, 1, 1)))
         hWorkVal = hWorkVal & Hex(AscB(MidB(StringIn, 1, 1)))
     End If
     End If
     '
     '
     ' Return Long Integer value.
     ' Return Long Integer value.
     MemStringToLong = CLng(&quot;&amp;H&quot; &amp; hWorkVal)
     MemStringToLong = CLng("&H" & hWorkVal)
End Function
End Function


Line 106: Line 106:
     '
     '
     ' Check to see if it is not zero.
     ' Check to see if it is not zero.
     If hWorkVal <&gt; &quot;0&quot; Then
     If hWorkVal <> "0" Then
         '
         '
         ' Convert to memory storage format (Little Endian).
         ' Convert to memory storage format (Little Endian).
         ' For example, 0000A411 would convert to 11A40000.
         ' For example, 0000A411 would convert to 11A40000.
         ' Use ChrB to rebuild Bytes.
         ' Use ChrB to rebuild Bytes.
         LongToMemoryString = ChrB(CInt(&quot;&amp;H&quot; &amp; Mid(hWorkVal, 3, 2)))
         LongToMemoryString = ChrB(CInt("&H" & Mid(hWorkVal, 3, 2)))
         LongToMemoryString = LongToMemoryString &amp; _
         LongToMemoryString = LongToMemoryString & _
                             ChrB(CInt(&quot;&amp;H&quot; &amp; Mid(hWorkVal, 1, 2)))
                             ChrB(CInt("&H" & Mid(hWorkVal, 1, 2)))
         LongToMemoryString = LongToMemoryString &amp; ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
         LongToMemoryString = LongToMemoryString &amp; ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
     Else
     Else
         ' Just return zeros.
         ' Just return zeros.
         ' Use ChrB to build Bytes.
         ' Use ChrB to build Bytes.
         LongToMemoryString = ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = ChrB(CInt("&H00"))
         LongToMemoryString = LongToMemoryString &amp; ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
         LongToMemoryString = LongToMemoryString &amp; ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
         LongToMemoryString = LongToMemoryString &amp; ChrB(CInt(&quot;&amp;H00&quot;))
         LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
     End If
     End If
End Function
End Function
Line 130: Line 130:
     '
     '
     ' Convert inbound Long Integers to a memory storage String format.
     ' Convert inbound Long Integers to a memory storage String format.
     RECT = LongToMemoryString(rLeft) &amp; _
     RECT = LongToMemoryString(rLeft) & _
           LongToMemoryString(rTop) &amp; _
           LongToMemoryString(rTop) & _
           LongToMemoryString(rRight) &amp; _
           LongToMemoryString(rRight) & _
           LongToMemoryString(rBottom)
           LongToMemoryString(rBottom)
End Function
End Function
Line 141: Line 141:
Private Sub Form_Load()
Private Sub Form_Load()
     Command1.Move 120, 120, 2000, 600
     Command1.Move 120, 120, 2000, 600
     Command1.Caption = &quot;Get Form1 RECT Info.&quot;
     Command1.Caption = "Get Form1 RECT Info."
End Sub
End Sub


Line 161: Line 161:
     '
     '
     ' Test return value.
     ' Test return value.
     If lRet &gt; 0 Then
     If lRet > 0 Then
         '
         '
         ' Convert String back to Long Integer.
         ' Convert String back to Long Integer.
Line 167: Line 167:
         '
         '
         ' Display results.
         ' Display results.
         sMessage = &quot;RECT is defined as follows:&quot; &amp; vbCrLf
         sMessage = "RECT is defined as follows:" & vbCrLf
         sMessage = sMessage &amp; &quot;Left: &quot; &amp; rLeft &amp; vbCrLf
         sMessage = sMessage & "Left: " & rLeft & vbCrLf
         sMessage = sMessage &amp; &quot;Top: &quot; &amp; rTop &amp; vbCrLf
         sMessage = sMessage & "Top: " & rTop & vbCrLf
         sMessage = sMessage &amp; &quot;Right: &quot; &amp; rRight &amp; vbCrLf
         sMessage = sMessage & "Right: " & rRight & vbCrLf
         sMessage = sMessage &amp; &quot;Bottom: &quot; &amp; rBottom
         sMessage = sMessage & "Bottom: " & rBottom
          
          
         MsgBox sMessage, vbOKOnly + vbInformation, &quot;Form Settings&quot;
         MsgBox sMessage, vbOKOnly + vbInformation, "Form Settings"
     Else
     Else
         MsgBox &quot;Call to GetWindowRect Failed.&quot;, _
         MsgBox "Call to GetWindowRect Failed.", _
             vbOKOnly + vbCritical, &quot;Failure&quot;
             vbOKOnly + vbCritical, "Failure"
     End If
     End If
End Sub
End Sub

Latest revision as of 13:48, 21 July 2020

Knowledge Base


How To Call an API That Uses Structures from eVB/VBCE6

Article ID: 241530

Article Last Modified on 8/19/2005



APPLIES TO

  • Microsoft Windows CE Toolkit for Visual Basic 6.0
  • Microsoft eMbedded Visual Basic 3.0



This article was previously published under Q241530

SUMMARY

"Currently there is no explicit support for user-defined data types (UDTs) in either eMbedded Visual Basic 3.0 (eVB) or the Microsoft Windows CE Toolkit for Visual Basic 6.0 (VBCE).

This article illustrates one approach to calling Windows CE APIs from eVB/VBCE applications that require the use of UDT structures. This method requires use of advanced manipulation techniques for storing this data in memory.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
WARNING: This article assumes advanced knowledge of user-defined data types and their use with Win32 API calls in Microsoft Visual Basic. This method is not supported by Microsoft.

A UDT is a data structure that can store multiple related variables of different types. UDTs are very useful when you want to pass several related pieces of information in one parameter of a function call. Unfortunately, because UDTs are not directly supported in either eVB or VBCE, this limits you to which API calls you can use from your eVB/VBCE programs.

As a workaround to this limitation, there is a way you can manipulate the data and coax the contents of your would-be UDTs into a String variable that can be passed into an API call in the same format as a UDT would pass them. This example shows how to convert Long Integer data types into a string format compatible with how data is stored in memory.

NOTE: Be careful with the Declaration statement in eVB/VBCE. The UDT should always be specified as a String passed ByVal. This is in contrast to what you find in the "API Text Viewer" viewing the Winceapi.txt file.

  1. Create a new Windows CE project in either Visual Basic or eMbedded Visual Basic. Form1 is created by default.
  2. On the Project menu, select Add Module to add a module. Module1 is created by default.
  3. Paste the the following code into Module1:

    Option Explicit
    '
    ' Note: lpRect is passed as ByVal.
    Declare Function GetWindowRect Lib "Coredll" ( _
        ByVal hwnd As Long, ByVal lpRect As String) As Long
    
    Public Function MemStringToLong(StringIn As String) As Long
        On Error Resume Next
        Dim hWorkVal As String
        '
        ' Convert the String back to Long Integer.
        ' Converting back to Big Endian format.
        hWorkVal = Hex(AscB(MidB(StringIn, 2, 1)))
        If Not Err Then
            hWorkVal = hWorkVal & Hex(AscB(MidB(StringIn, 1, 1)))
        End If
        '
        ' Return Long Integer value.
        MemStringToLong = CLng("&H" & hWorkVal)
    End Function
    
    Public Sub getRECT(ByVal sRect As String, _
                       ByRef rLeft As Long, ByRef rTop As Long, _
                       ByRef rRight As Long, ByRef rBottom As Long)
        '
        ' Convert memory-formatted String back to Long Integer.
        rLeft = MemStringToLong(MidB(sRect, 1, 4))
        rTop = MemStringToLong(MidB(sRect, 5, 4))
        rRight = MemStringToLong(MidB(sRect, 9, 4))
        rBottom = MemStringToLong(MidB(sRect, 13, 4))
    End Sub
    
    Public Function LongToMemoryString(ByVal lInputValue As Long) As String
    
        Dim hWorkVal As String
        '
        ' Convert to HEX value.
        hWorkVal = Hex(lInputValue)
        '
        ' Check to see if it is not zero.
        If hWorkVal <> "0" Then
            '
            ' Convert to memory storage format (Little Endian).
            ' For example, 0000A411 would convert to 11A40000.
            ' Use ChrB to rebuild Bytes.
            LongToMemoryString = ChrB(CInt("&H" & Mid(hWorkVal, 3, 2)))
            LongToMemoryString = LongToMemoryString & _
                                 ChrB(CInt("&H" & Mid(hWorkVal, 1, 2)))
            LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
            LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
        Else
            ' Just return zeros.
            ' Use ChrB to build Bytes.
            LongToMemoryString = ChrB(CInt("&H00"))
            LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
            LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
            LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
        End If
    End Function
    
    Public Function RECT(rLeft As Long, rTop As Long, _
                         rRight As Long, rBottom As Long) As String
        '
        ' Convert inbound Long Integers to a memory storage String format.
        RECT = LongToMemoryString(rLeft) & _
               LongToMemoryString(rTop) & _
               LongToMemoryString(rRight) & _
               LongToMemoryString(rBottom)
    End Function
                        
  4. Add a Command button to Form1.
  5. Paste the following code into Form1:

    Option Explicit
    Private Sub Form_Load()
        Command1.Move 120, 120, 2000, 600
        Command1.Caption = "Get Form1 RECT Info."
    End Sub
    
    Private Sub Command1_Click()
        Dim lRet As Long
        Dim sMessage  As String
        Dim sRect As String
        Dim rLeft As Long
        Dim rTop As Long
        Dim rRight  As Long
        Dim rBottom  As Long
        '
        ' Initialize RECT memory string.
        ' Convert initial Rect values to String to pass into GetWindowRect API.
        sRect = RECT(rLeft, rTop, rRight, rBottom)
        '
        ' Call GetWindowRect.
        lRet = GetWindowRect(Me.hwnd, sRect)
        '
        ' Test return value.
        If lRet > 0 Then
            '
            ' Convert String back to Long Integer.
            getRECT sRect, rLeft, rTop, rRight, rBottom
            '
            ' Display results.
            sMessage = "RECT is defined as follows:" & vbCrLf
            sMessage = sMessage & "Left: " & rLeft & vbCrLf
            sMessage = sMessage & "Top: " & rTop & vbCrLf
            sMessage = sMessage & "Right: " & rRight & vbCrLf
            sMessage = sMessage & "Bottom: " & rBottom
            
            MsgBox sMessage, vbOKOnly + vbInformation, "Form Settings"
        Else
            MsgBox "Call to GetWindowRect Failed.", _
                vbOKOnly + vbCritical, "Failure"
        End If
    End Sub
                        
  6. Run the application.
  7. Click on the Command button and note the results.


REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

102025 Explanation of Big Endian and Little Endian Architecture


For more information, please see the MSDN:


Additional query words: vbce6 vcce6 wce eVB

Keywords: kbhowto kbapi kbtoolkit KB241530