vbAccelerator - Contents of code file: mIMAPI.bas

This file is part of the download VB5 IMAPI Library Source, which is described in the article Image Mastering API (IMAPI) Library for VB.

Attribute VB_Name = "mIMAPI"
Option Explicit

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As
 Any, lpvSource As Any, ByVal cbCopy As Long)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long

Private Const FAIL_BIT As Long = &H80000000

Public Function FAILED(ByVal HRESULT As Long) As Boolean
End Function

Public Function lpwstrPtrToString(ByVal lpwstrPtr As Long) As String
Dim lSize As Long
   If Not (lpwstrPtr = 0) Then
      lSize = lstrlenW(ByVal lpwstrPtr)
      If (lSize > 0) Then
         ReDim b(0 To (lSize * 2) - 1) As Byte
         CopyMemory b(0), ByVal lpwstrPtr, lSize * 2
         lpwstrPtrToString = b
      End If
   End If
End Function

Public Function UUIDAsString(theUuid As UUID) As String
Dim sUuid As String
Dim iData As Long
   sUuid = PadHex(theUuid.Data1, 8) & "-" & PadHex(theUuid.Data2, 4) & "-" &
    PadHex(theUuid.Data3, 4) & "-"
   For iData = 0 To 7
      If (iData = 2) Then
         sUuid = sUuid & "-"
      End If
      sUuid = sUuid & PadHex(theUuid.Data4(iData), 2)
   Next iData
   UUIDAsString = sUuid
End Function

Private Function PadHex(ByVal lValue As Long, ByVal lDigits As Long) As String
Dim sHex As String
   sHex = Hex(lValue)
   If Len(sHex) < lDigits Then
      sHex = String(lDigits - Len(sHex), "0") & sHex
   End If
   PadHex = sHex
End Function

Public Function MAKE_HRESULT(ByVal severity As Long, ByVal facility As Long,
 ByVal code As Long) As Long
Dim hR As Long
   If (severity = 1) Then
      hR = &H80000000
   End If
   hR = hR Or (facility And &HFFF&) * &H10000
   hR = hR Or code
End Function