home *** CD-ROM | disk | FTP | other *** search
- '########## HUGEARR -- Huge Array Functions -- Module
- 'This declaration file contains the original names for these functions.
- Declare Function HugeDim% Lib "hugearr.dll" Alias "VBHugeDim" (ByVal recsize%, ByVal limit&)
- Declare Function HugeRedim% Lib "hugearr.dll" Alias "VBHugeRedim" (ByVal hArray%, ByVal limit&)
- Declare Function HugeErase% Lib "hugearr.dll" Alias "VBHugeErase" (ByVal hArray%)
- Declare Function GetHugeEl% Lib "hugearr.dll" Alias "VBHugeGet" (ByVal Index%, ByVal el&, buffer As Any)
- Declare Function GetHugeNEl% Lib "hugearr.dll" Alias "VBHugeGetNum" (ByVal Index%, ByVal el&, ByVal nelem%, buffer As Any)
- Declare Function HugeInt% Lib "hugearr.dll" Alias "VBHugeGetInt" (ByVal hArray%, ByVal el&)
- Declare Function HugeLong& Lib "hugearr.dll" Alias "VBHugeGetLong" (ByVal hArray%, ByVal el&)
- Declare Function HugeSingle! Lib "hugearr.dll" Alias "VBHugeGetSingle" (ByVal hArray%, ByVal el&)
- Declare Function HugeDouble# Lib "hugearr.dll" Alias "VBHugeGetDouble" (ByVal hArray%, ByVal el&)
- Declare Function HugeCurrency@ Lib "hugearr.dll" Alias "VBHugeGetCurrency" (ByVal hArray%, ByVal el&)
- Declare Function NumHugeArrays% Lib "hugearr.dll" Alias "VBHugeNumArrays" ()
- Declare Function HugeUbound& Lib "hugearr.dll" Alias "VBHugeUBound" (ByVal hArray%)
- Declare Function HugeLoad& Lib "hugearr.dll" Alias "VBHugeLoad" (ByVal hArray%, ByVal RecLen%, ByVal Fn$)
- Declare Function HugeSave& Lib "hugearr.dll" Alias "VBHugeSave" (ByVal hArray%, ByVal NEl&, ByVal RecLen%, ByVal Fn$)
- Declare Function SetHugeEl% Lib "hugearr.dll" Alias "VBHugeSet" (ByVal Index%, ByVal el&, buffer As Any)
- Declare Function SetHugeNEl% Lib "hugearr.dll" Alias "VBHugeSetNum" (ByVal Index%, ByVal el&, ByVal nelem%, buffer As Any)
-
- '################# new functions from hstrcat.c ###########################
- Declare Function VBHugeStrCat Lib "HUGEARR.DLL" (ByVal dest As Any, ByVal src As String) As Long
- Declare Function VBHugeStrEnd Lib "HUGEARR.DLL" (ByVal hMem As Integer) As Long
- Declare Function VBHugeLock Lib "HUGEARR.DLL" (ByVal hMem%) As Long
-
- Declare Function GetActiveWindow Lib "User" () As Integer
- Declare Function lstrcpy Lib "Kernel" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
- Declare Function AnsiPrev Lib "User" (ByVal lpString As String, ByVal lpString As String) As Long
-
- '============ clipboard functions
- Declare Function EmptyClipboard Lib "User" () As Integer
- Declare Function OpenClipboard Lib "User" (ByVal hWnd As Integer) As Integer
- Declare Function CloseClipboard Lib "User" () As Integer
- Declare Function SetClipboardData Lib "User" (ByVal wFormat As Integer, ByVal hMem As Integer) As Integer
- Declare Function GetClipboardData Lib "User" (ByVal wFormat As Integer) As Integer
-
- '=============================================
- Declare Function GlobalAlloc Lib "Kernel" (ByVal wFlags As Integer, ByVal dwBytes As Long) As Integer
- Declare Function GlobalCompact Lib "Kernel" (ByVal dwMinFree As Long) As Long
- Declare Function GlobalFree Lib "Kernel" (ByVal hMem As Integer) As Integer
- Declare Function GlobalHandle Lib "Kernel" (ByVal wMem As Integer) As Long
- Declare Function GlobalLock Lib "Kernel" (ByVal hMem As Integer) As Long
- Declare Function GlobalReAlloc Lib "Kernel" (ByVal hMem As Integer, ByVal dwBytes As Long, ByVal wFlags As Integer) As Integer
-
- 'NOTE: instead of declaring the function GlobalDiscard and calling
- ' GlobalDiscard(hMem), call GlobalReAlloc(hMem, 0, GMEM_MOVEABLE)
- Declare Function GlobalSize Lib "Kernel" (ByVal hMem As Integer) As Long
- Declare Function GlobalUnlock Lib "Kernel" (ByVal hMem As Integer) As Integer
- Declare Function hmemcpy Lib "Kernel" (ByVal lpdest As Any, ByVal lpsource As Any, ByVal length As Long) As Long
- '====================================================
-
- '==========================================================
- Function BuildHuge& ()
-
- Dim rocnt%
- MEM_CHUNKS& = 64000
-
- numcols% = 20
- roww$ = String$(2000, Chr$(0)) ' allocate space for 1 row of data
-
- NL$ = Chr$(13) + Chr$(10) 'CRLF
- TABKEY$ = Chr$(9) 'tab character
-
- '============================================
- Rem ====== allocate initial block of memory for all of data
- numallocs& = 1
- mem_sp& = MEM_CHUNKS& * numallocs&
- hMem% = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, ByVal mem_sp&)
- If hMem% = 0 Then
- MsgBox "Can't Do initial memory allocation"
- SQLQuery = 0
- Exit Function
- End If
- lptrStart& = VBHugeLock(ByVal hMem%)
- If lptrStart& = 0 Then
- MsgBox "Can't do initial memory allocation"
- SQLQuery = 0
- Exit Function
- End If
- lptr& = lptrStart& 'initialize pointer
- memused& = 0
-
- '==== init string
- For rocnt% = 1 To 500
- ' roww$ = Str$(rocnt%) + TABKEY$
- roww$ = ""
-
- '=== build a row of test data
- For x% = 1 To numcols%
- colval$ = "R" + Str$(rocnt%) + "C" + Str$(x%)
- roww$ = roww$ + colval$ + TABKEY$
- Next x%
-
- Rem === add crlf
- roww$ = roww$ + NL$ ' add CRLF
- length = Len(roww$)
-
- Rem === calculate used memory
- If (memused& + length + 2) >= mem_sp& Then
- MsgBox "doing a realloc"
- numallocs& = numallocs& + 1
- mem_sp& = MEM_CHUNKS& * numallocs&
- hMem% = GlobalReAlloc(ByVal hMem%, mem_sp&, GMEM_MOVEABLE)
- If hMem% = 0 Then
- MsgBox "Can't Reallocate memory"
- SQLQuery = 0
- ret% = GlobalFree(ByVal hMem%)
- Exit Function
- End If
- lptrStart& = VBHugeLock(ByVal hMem%)
- If lptrStart& = 0 Then
- ret% = GlobalFree(ByVal hMem%)
- MsgBox "Can't Do a Reallocate"
- SQLQuery = 0
- Exit Function
- End If
- lptr& = VBHugeStrEnd&(ByVal hMem%) 'find new end of string
- End If ' =============== end of realloc
-
- Rem ====== concatanate new row of data to old one
- lptr& = VBHugeStrCat&(lptr&, ByVal roww$)
- memused& = memused& + length
-
- Next rocnt% 'row loop counter
-
- MsgBox "memory used= " + Str$(memused&)
- '============= get size of data and allocate clipboard memory
- lSize& = GlobalSize(hMem%) + 5
-
- hClipMem% = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, lSize&)
- If hClipMem% = 0 Then
- MsgBox "Can't allocate memory for Clipboard"
- SQLQuery = 0
- Exit Function
- End If
- lpClipData& = VBHugeLock(hClipMem%)
- If lpClipData& = 0 Then
- MsgBox "Can't allocate memory for Clipboard"
- SQLQuery = 0
- Exit Function
- End If
-
- '=== copy data to clipboard memory
- lptrStart& = VBHugeLock(hMem%) 'get start address
- old& = hmemcpy(lpClipData&, lptrStart&, memused&)
-
- ret% = GlobalUnlock(hMem%) 'release handle
- ret% = GlobalUnlock(hClipMem%) 'release handle
- hWnd% = GetActiveWindow()
- If (OpenClipboard(hWnd%)) Then
- MsgBox "Opening clipboard"
- ret% = EmptyClipboard()
- ret% = SetClipboardData(CF_TEXT, hClipMem%)
- ret% = CloseClipboard()
- End If
- st% = GlobalFree(hMem%) 'free memory
-
- BuildHuge = rocnt% - 1
- End Function
-
-