Current area: HOME ->

Zip File view

Store large chunks of binary data in memory


This page allows you to view the contents of a file contained inside a ZIP archive available at Programmer's Heaven. This means you can view the code and find what you need from it without having to download the ZIP file first. If the file contains source code for a language we recognize, we have syntax highlighted it.

Filename displayed: BIN2MEM.BAS
Found in file: BIN2MEM.ZIP

Download: Fakedemo by Pelusa  w. Full source
OPTION Compare Database   'Use database order for string comparisons
OPTION Explicit : DEFINT A-Z

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
DECLARE FUNCTION GlobalUnlock Lib "Kernel" (BYVAL hMem AS INTEGER) AS INTEGER

' Global Memory Flags
Global CONST GMEM_FIXED = &H0
Global CONST GMEM_MOVEABLE = &H2
Global CONST GMEM_NOCOMPACT = &H10
Global CONST GMEM_NODISCARD = &H20
Global CONST GMEM_ZEROINIT = &H40
Global CONST GMEM_MODIFY = &H80
Global CONST GMEM_DISCARDABLE = &H100
Global CONST GMEM_NOT_BANKED = &H1000
Global CONST GMEM_SHARE = &H2000
Global CONST GMEM_DDESHARE = &H2000
Global CONST GMEM_NOTIFY = &H4000
Global CONST GMEM_LOWER = GMEM_NOT_BANKED
Global CONST GHND = (GMEM_MOVEABLE OR GMEM_ZEROINIT)
Global CONST GPTR = (GMEM_FIXED OR GMEM_ZEROINIT)
'NOTE: instead of declaring the function GlobalDiscard and calling
'      GlobalDiscard(hMem), call GlobalReAlloc(hMem, 0, GMEM_MOVEABLE)

DECLARE FUNCTION MemoryRead Lib "Toolhelp.dll" (BYVAL wSel AS INTEGER, BYVAL dwOffset AS LONG, BYVAL lpvBuf AS STRING, BYVAL dwcb AS LONG) AS INTEGER
DECLARE FUNCTION MemoryWrite Lib "Toolhelp.dll" (BYVAL wSel AS INTEGER, BYVAL dwOffset AS LONG, BYVAL lpvBuf AS STRING, BYVAL dwcb AS LONG) AS INTEGER

DECLARE FUNCTION sndPlaySound Lib "MMSYSTEM" (BYVAL lpszSoundName AS ANY, BYVAL uFlags AS INTEGER) AS INTEGER
'  flag values for wFlags parameter
Global CONST SND_SYNC = &H0                 '  play synchronously (default)
Global CONST SND_ASYNC = &H1                '  play asynchronously
Global CONST SND_NODEFAULT = &H2            '  don't use default sound
Global CONST SND_MEMORY = &H4               '  lpszSoundName points to a memory file
Global CONST SND_LOOP = &H8                 '  loop the sound until next sndPlaySound
Global CONST SND_NOSTOP = &H10              '  don't stop any currently playing sound

'Play a sound
SUB ExecAssoc (BYVAL KEY AS STRING)
    DIM DB AS Database: Set DB = CurrentDB()
    DIM T AS Table: Set T = DB.OpenTable("associations")
    T.index = "primarykey"
    T.SEEK "=", KEY
    IF (T.nomatch) THEN ERROR 32767

    DIM DL AS LONG: DL = T.[DATA].FieldSize()
    DIM handle AS INTEGER: handle = GlobalAlloc(GMEM_FIXED, DL)
    Debug.PRINT "DL = " & DL & ", handle = " & HEX$(handle)
    IF (handle < 1) THEN ERROR 32767
    DIM pointer AS LONG: pointer = GlobalLock(handle)
    Debug.PRINT "pointer = " & HEX$(pointer)
    DIM i AS LONG: i = 0
    WHILE (i < DL)
        DIM chunk AS STRING: chunk = T.[DATA].GetChunk(i, IIf(DL - i > 16384, 16384, DL - i))
        DIM r AS INTEGER: r = MemoryWrite(handle, i, chunk, LEN(chunk))
        i = i + LEN(chunk)
    WEND
    r = sndPlaySound(pointer, SND_SYNC + SND_MEMORY + SND_NOSTOP)
    r = GlobalUnlock(handle)
    r = GlobalFree(handle)

    'This next seems to prevent the above from becoming the Windows default
    r = sndPlaySound(SPACE$(128), SND_SYNC + SND_MEMORY + SND_NOSTOP + SND_NODEFAULT)
END SUB

'Load a new sound into the table
SUB LoadAssoc (BYVAL KEY AS STRING, BYVAL path AS STRING)
    DIM DB AS Database: Set DB = CurrentDB()
    DIM T AS Table: Set T = DB.OpenTable("associations")
    DIM fd AS INTEGER: fd = FREEFILE
    OPEN path FOR BINARY ACCESS READ LOCK WRITE AS #fd
    DIM FL AS LONG: FL = LOF(fd)
    T.AddNew
    T.[KEY] = KEY
    T.[DATA] = Null
    WHILE (FL > 0)
        DIM buffer AS STRING: buffer = SPACE$(IIf(FL > 4096, 4096, FL))
        GET #fd, , buffer: FL = FL - LEN(buffer)
        Debug.PRINT LEN(buffer) & " bytes read"
        T.[DATA].AppendChunk (buffer)
    WEND
    CLOSE #fd
    T.Update
    T.CLOSE
    DB.CLOSE
END SUB


About Magic v1.0
The purpose of About Magic is the aid developers in the creation of a great About Box. This control has a the necessary information to have a professional looking About box like Microsoft Windo...
BOBOLI THE MIGHTY KNIGHT Networked Medieval Conflict
Game with C source
Fakedemo by Pelusa w. Full source

Download About Magic v1.0 The purpose of About Magic is the aid developers in the  creation of a great About Box. This control has a the necessary  information to have a professional looking About box like  Microsoft Windo... Download BOBOLI THE MIGHTY KNIGHT Networked Medieval Conflict Game with C source Download Fakedemo by Pelusa  w. Full source







Sponsored links

Localize software in three simple steps
Localize .Net, C/C++ & Delphi apps visually. HTML, HTML Help, XML & databases. Try Sisulizer now!
Delphi Localization Tool Sisulizer (WYSIWYG)
Create multilingual Delphi apps in three simple steps. Localize XML, HTML Help ... Try Sisulizer now
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
Computer Professionals: Are you owed Overtime?
Federal and State Laws may allow computer professionals to collect overtime. Our law firm is experienced, and has initiated class action lawsuits against some of the largest computer companies to collect back pay and overtime. Strictly Confidential.
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.