Mapping a drive letter to a memory location?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Mapping a drive letter to a memory location?

  1. #1
    Pino Carafa Guest

    Mapping a drive letter to a memory location?

    Is it possible to map a drive letter to a location in RAM through API, so
    that I can create temporary files which are really fast to access?

    How?

    --
    Inside, I'm screaming
    --



  2. #2
    reese hodge Guest

    Re: Mapping a drive letter to a memory location?


    Have you tried using a ramdrive? You could create a new one and map a drive
    to that....


    "Pino Carafa" <deathtospammers@eircom.net> wrote:
    >Is it possible to map a drive letter to a location in RAM through API, so
    >that I can create temporary files which are really fast to access?
    >
    >How?
    >
    >--
    >Inside, I'm screaming
    >--
    >
    >



  3. #3
    reese hodge Guest

    Re: Mapping a drive letter to a memory location?


    Have you tried using a ramdrive? You could create a new one and map a drive
    to that....


    "Pino Carafa" <deathtospammers@eircom.net> wrote:
    >Is it possible to map a drive letter to a location in RAM through API, so
    >that I can create temporary files which are really fast to access?
    >
    >How?
    >
    >--
    >Inside, I'm screaming
    >--
    >
    >



  4. #4
    Bill McCarthy Guest

    Re: Mapping a drive letter to a memory location?

    In windows, RAM disks are not really appropiate (I'm not sure if they are
    even still supported). Either just load/store your data as a variable, or
    you could also use a MemoryMapped file. In July's VBPJ I wrote an article
    about using pointer's in VB, and one of the samples is using MM files, so
    you might want to have a look at that, and also see www.mvps.org/vb for a
    sample of using MM files.



    "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    news:3980542f$1@news.devx.com...
    > Is it possible to map a drive letter to a location in RAM through API, so
    > that I can create temporary files which are really fast to access?
    >
    > How?
    >
    > --
    > Inside, I'm screaming
    > --
    >
    >




  5. #5
    Bill McCarthy Guest

    Re: Mapping a drive letter to a memory location?

    In windows, RAM disks are not really appropiate (I'm not sure if they are
    even still supported). Either just load/store your data as a variable, or
    you could also use a MemoryMapped file. In July's VBPJ I wrote an article
    about using pointer's in VB, and one of the samples is using MM files, so
    you might want to have a look at that, and also see www.mvps.org/vb for a
    sample of using MM files.



    "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    news:3980542f$1@news.devx.com...
    > Is it possible to map a drive letter to a location in RAM through API, so
    > that I can create temporary files which are really fast to access?
    >
    > How?
    >
    > --
    > Inside, I'm screaming
    > --
    >
    >




  6. #6
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    OK, here's the scenario.

    I'm using this arcane piece of **** software that allows you to add
    documents to some archive, right....

    It has some sort of "adddocument" method, in which you specify the filename
    of the document that you want to put into the archive.

    All well and good if your document happens to be a file on a disk, but if
    I've just created a lovely XML document, it annoys me that I *first* have to
    dump it on to my hard disk so that some other software can then proceed and
    read it from the disk again and put it into its archived. I'd prefer it if I
    could avoid the two disk access steps. I have no control over that software,
    so I thought the next best thing might be to pretend something is a disk,
    when really it isn't. Hence my question.

    Any ideas?

    --
    Inside, I'm screaming
    --
    "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    news:39806315@news.devx.com...
    > In windows, RAM disks are not really appropiate (I'm not sure if they are
    > even still supported). Either just load/store your data as a variable, or
    > you could also use a MemoryMapped file. In July's VBPJ I wrote an article
    > about using pointer's in VB, and one of the samples is using MM files, so
    > you might want to have a look at that, and also see www.mvps.org/vb for a
    > sample of using MM files.
    >
    >
    >
    > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > news:3980542f$1@news.devx.com...
    > > Is it possible to map a drive letter to a location in RAM through API,

    so
    > > that I can create temporary files which are really fast to access?
    > >
    > > How?
    > >
    > > --
    > > Inside, I'm screaming
    > > --
    > >
    > >

    >
    >




  7. #7
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    OK, here's the scenario.

    I'm using this arcane piece of **** software that allows you to add
    documents to some archive, right....

    It has some sort of "adddocument" method, in which you specify the filename
    of the document that you want to put into the archive.

    All well and good if your document happens to be a file on a disk, but if
    I've just created a lovely XML document, it annoys me that I *first* have to
    dump it on to my hard disk so that some other software can then proceed and
    read it from the disk again and put it into its archived. I'd prefer it if I
    could avoid the two disk access steps. I have no control over that software,
    so I thought the next best thing might be to pretend something is a disk,
    when really it isn't. Hence my question.

    Any ideas?

    --
    Inside, I'm screaming
    --
    "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    news:39806315@news.devx.com...
    > In windows, RAM disks are not really appropiate (I'm not sure if they are
    > even still supported). Either just load/store your data as a variable, or
    > you could also use a MemoryMapped file. In July's VBPJ I wrote an article
    > about using pointer's in VB, and one of the samples is using MM files, so
    > you might want to have a look at that, and also see www.mvps.org/vb for a
    > sample of using MM files.
    >
    >
    >
    > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > news:3980542f$1@news.devx.com...
    > > Is it possible to map a drive letter to a location in RAM through API,

    so
    > > that I can create temporary files which are really fast to access?
    > >
    > > How?
    > >
    > > --
    > > Inside, I'm screaming
    > > --
    > >
    > >

    >
    >




  8. #8
    Bill McCarthy Guest

    Re: Mapping a drive letter to a memory location?

    In that case if the other app won't accept a handle, you could try using the
    createfile api and setting the FILE_ATTRIBUTE_TEMPORARY flag.


    "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    news:39806b97@news.devx.com...
    > OK, here's the scenario.
    >
    > I'm using this arcane piece of **** software that allows you to add
    > documents to some archive, right....
    >
    > It has some sort of "adddocument" method, in which you specify the

    filename
    > of the document that you want to put into the archive.
    >
    > All well and good if your document happens to be a file on a disk, but if
    > I've just created a lovely XML document, it annoys me that I *first* have

    to
    > dump it on to my hard disk so that some other software can then proceed

    and
    > read it from the disk again and put it into its archived. I'd prefer it if

    I
    > could avoid the two disk access steps. I have no control over that

    software,
    > so I thought the next best thing might be to pretend something is a disk,
    > when really it isn't. Hence my question.
    >
    > Any ideas?
    >
    > --
    > Inside, I'm screaming
    > --
    > "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    > news:39806315@news.devx.com...
    > > In windows, RAM disks are not really appropiate (I'm not sure if they

    are
    > > even still supported). Either just load/store your data as a variable,

    or
    > > you could also use a MemoryMapped file. In July's VBPJ I wrote an

    article
    > > about using pointer's in VB, and one of the samples is using MM files,

    so
    > > you might want to have a look at that, and also see www.mvps.org/vb for

    a
    > > sample of using MM files.
    > >
    > >
    > >
    > > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > > news:3980542f$1@news.devx.com...
    > > > Is it possible to map a drive letter to a location in RAM through API,

    > so
    > > > that I can create temporary files which are really fast to access?
    > > >
    > > > How?
    > > >
    > > > --
    > > > Inside, I'm screaming
    > > > --
    > > >
    > > >

    > >
    > >

    >
    >




  9. #9
    Bill McCarthy Guest

    Re: Mapping a drive letter to a memory location?

    In that case if the other app won't accept a handle, you could try using the
    createfile api and setting the FILE_ATTRIBUTE_TEMPORARY flag.


    "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    news:39806b97@news.devx.com...
    > OK, here's the scenario.
    >
    > I'm using this arcane piece of **** software that allows you to add
    > documents to some archive, right....
    >
    > It has some sort of "adddocument" method, in which you specify the

    filename
    > of the document that you want to put into the archive.
    >
    > All well and good if your document happens to be a file on a disk, but if
    > I've just created a lovely XML document, it annoys me that I *first* have

    to
    > dump it on to my hard disk so that some other software can then proceed

    and
    > read it from the disk again and put it into its archived. I'd prefer it if

    I
    > could avoid the two disk access steps. I have no control over that

    software,
    > so I thought the next best thing might be to pretend something is a disk,
    > when really it isn't. Hence my question.
    >
    > Any ideas?
    >
    > --
    > Inside, I'm screaming
    > --
    > "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    > news:39806315@news.devx.com...
    > > In windows, RAM disks are not really appropiate (I'm not sure if they

    are
    > > even still supported). Either just load/store your data as a variable,

    or
    > > you could also use a MemoryMapped file. In July's VBPJ I wrote an

    article
    > > about using pointer's in VB, and one of the samples is using MM files,

    so
    > > you might want to have a look at that, and also see www.mvps.org/vb for

    a
    > > sample of using MM files.
    > >
    > >
    > >
    > > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > > news:3980542f$1@news.devx.com...
    > > > Is it possible to map a drive letter to a location in RAM through API,

    > so
    > > > that I can create temporary files which are really fast to access?
    > > >
    > > > How?
    > > >
    > > > --
    > > > Inside, I'm screaming
    > > > --
    > > >
    > > >

    > >
    > >

    >
    >




  10. #10
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    OK, Thanks Bill..

    In my next comment I am going to show you some code.

    Can you just check it for me quickly, and tell me whether I'm right.

    So, I'm using CreateFile to create a file, and I'm setting the
    FILE_ATTRIBUTE_TEMPORARY flag.

    Am I right then in assuming that between the CloseHandle and the Kill
    statements the file is *not* actually written to the disk, but is held in
    memory?

    That would be exactly what I'd need.

    Cheers

    Code follows in reply

    --
    Inside, I'm screaming
    --
    "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    news:398072b2@news.devx.com...
    > In that case if the other app won't accept a handle, you could try using

    the
    > createfile api and setting the FILE_ATTRIBUTE_TEMPORARY flag.
    >
    >
    > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > news:39806b97@news.devx.com...
    > > OK, here's the scenario.
    > >
    > > I'm using this arcane piece of **** software that allows you to add
    > > documents to some archive, right....
    > >
    > > It has some sort of "adddocument" method, in which you specify the

    > filename
    > > of the document that you want to put into the archive.
    > >
    > > All well and good if your document happens to be a file on a disk, but

    if
    > > I've just created a lovely XML document, it annoys me that I *first*

    have
    > to
    > > dump it on to my hard disk so that some other software can then proceed

    > and
    > > read it from the disk again and put it into its archived. I'd prefer it

    if
    > I
    > > could avoid the two disk access steps. I have no control over that

    > software,
    > > so I thought the next best thing might be to pretend something is a

    disk,
    > > when really it isn't. Hence my question.
    > >
    > > Any ideas?
    > >
    > > --
    > > Inside, I'm screaming
    > > --
    > > "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    > > news:39806315@news.devx.com...
    > > > In windows, RAM disks are not really appropiate (I'm not sure if they

    > are
    > > > even still supported). Either just load/store your data as a variable,

    > or
    > > > you could also use a MemoryMapped file. In July's VBPJ I wrote an

    > article
    > > > about using pointer's in VB, and one of the samples is using MM files,

    > so
    > > > you might want to have a look at that, and also see www.mvps.org/vb

    for
    > a
    > > > sample of using MM files.
    > > >
    > > >
    > > >
    > > > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > > > news:3980542f$1@news.devx.com...
    > > > > Is it possible to map a drive letter to a location in RAM through

    API,
    > > so
    > > > > that I can create temporary files which are really fast to access?
    > > > >
    > > > > How?
    > > > >
    > > > > --
    > > > > Inside, I'm screaming
    > > > > --
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




  11. #11
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    OK, Thanks Bill..

    In my next comment I am going to show you some code.

    Can you just check it for me quickly, and tell me whether I'm right.

    So, I'm using CreateFile to create a file, and I'm setting the
    FILE_ATTRIBUTE_TEMPORARY flag.

    Am I right then in assuming that between the CloseHandle and the Kill
    statements the file is *not* actually written to the disk, but is held in
    memory?

    That would be exactly what I'd need.

    Cheers

    Code follows in reply

    --
    Inside, I'm screaming
    --
    "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    news:398072b2@news.devx.com...
    > In that case if the other app won't accept a handle, you could try using

    the
    > createfile api and setting the FILE_ATTRIBUTE_TEMPORARY flag.
    >
    >
    > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > news:39806b97@news.devx.com...
    > > OK, here's the scenario.
    > >
    > > I'm using this arcane piece of **** software that allows you to add
    > > documents to some archive, right....
    > >
    > > It has some sort of "adddocument" method, in which you specify the

    > filename
    > > of the document that you want to put into the archive.
    > >
    > > All well and good if your document happens to be a file on a disk, but

    if
    > > I've just created a lovely XML document, it annoys me that I *first*

    have
    > to
    > > dump it on to my hard disk so that some other software can then proceed

    > and
    > > read it from the disk again and put it into its archived. I'd prefer it

    if
    > I
    > > could avoid the two disk access steps. I have no control over that

    > software,
    > > so I thought the next best thing might be to pretend something is a

    disk,
    > > when really it isn't. Hence my question.
    > >
    > > Any ideas?
    > >
    > > --
    > > Inside, I'm screaming
    > > --
    > > "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote in message
    > > news:39806315@news.devx.com...
    > > > In windows, RAM disks are not really appropiate (I'm not sure if they

    > are
    > > > even still supported). Either just load/store your data as a variable,

    > or
    > > > you could also use a MemoryMapped file. In July's VBPJ I wrote an

    > article
    > > > about using pointer's in VB, and one of the samples is using MM files,

    > so
    > > > you might want to have a look at that, and also see www.mvps.org/vb

    for
    > a
    > > > sample of using MM files.
    > > >
    > > >
    > > >
    > > > "Pino Carafa" <deathtospammers@eircom.net> wrote in message
    > > > news:3980542f$1@news.devx.com...
    > > > > Is it possible to map a drive letter to a location in RAM through

    API,
    > > so
    > > > > that I can create temporary files which are really fast to access?
    > > > >
    > > > > How?
    > > > >
    > > > > --
    > > > > Inside, I'm screaming
    > > > > --
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




  12. #12
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    Option Explicit

    Private Const READ_CONTROL As Long = &H20000
    Private Const DELETE As Long = &H10000
    Private Const WRITE_DAC As Long = &H40000
    Private Const WRITE_OWNER As Long = &H80000
    Private Const SYNCHRONIZE As Long = &H100000
    Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
    Private Const STANDARD_RIGHTS_READ As Long = &H20000
    Private Const STANDARD_RIGHTS_WRITE As Long = &H20000
    Private Const STANDARD_RIGHTS_EXECUTE As Long = &H20000
    Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
    Private Const SPECIFIC_RIGHTS_ALL As Long = &HFFFF
    '
    ' AccessSystemAcl access type
    '
    Private Const ACCESS_SYSTEM_SECURITY As Long = &H1000000
    '
    ' MaximumAllowed access type
    '
    Private Const MAXIMUM_ALLOWED As Long = &H2000000
    '
    ' These are the generic rights.
    '
    Private Const GENERIC_READ As Long = &H80000000
    Private Const GENERIC_WRITE As Long = &H40000000
    Private Const GENERIC_EXECUTE As Long = &H20000000
    Private Const GENERIC_ALL As Long = &H10000000

    Private Const FILE_SHARE_READ As Long = &H1
    Private Const FILE_SHARE_WRITE As Long = &H2
    Private Const FILE_SHARE_DELETE As Long = &H4

    Private Const FILE_ATTRIBUTE_READONLY As Long = &H1
    Private Const FILE_ATTRIBUTE_HIDDEN As Long = &H2
    Private Const FILE_ATTRIBUTE_SYSTEM As Long = &H4
    Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
    Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20
    Private Const FILE_ATTRIBUTE_ENCRYPTED As Long = &H40
    Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
    Private Const FILE_ATTRIBUTE_TEMPORARY As Long = &H100
    Private Const FILE_ATTRIBUTE_SPARSE_FILE As Long = &H200
    Private Const FILE_ATTRIBUTE_REPARSE_POINT As Long = &H400
    Private Const FILE_ATTRIBUTE_COMPRESSED As Long = &H800
    Private Const FILE_ATTRIBUTE_OFFLINE As Long = &H1000
    Private Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED As Long = &H2000

    Private Const CREATE_NEW As Long = 1
    Private Const CREATE_ALWAYS As Long = 2
    Private Const OPEN_EXISTING As Long = 3
    Private Const OPEN_ALWAYS As Long = 4
    Private Const TRUNCATE_EXISTING As Long = 5

    Private Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
    Private Const FILE_FLAG_OVERLAPPED As Long = &H40000000
    Private Const FILE_FLAG_NO_BUFFERING As Long = &H20000000
    Private Const FILE_FLAG_RANDOM_ACCESS As Long = &H10000000
    Private Const FILE_FLAG_SEQUENTIAL_SCAN As Long = &H8000000
    Private Const FILE_FLAG_DELETE_ON_CLOSE As Long = &H4000000
    Private Const FILE_FLAG_BACKUP_SEMANTICS As Long = &H2000000
    Private Const FILE_FLAG_POSIX_SEMANTICS As Long = &H1000000
    Private Const FILE_FLAG_OPEN_REPARSE_POINT As Long = &H200000
    Private Const FILE_FLAG_OPEN_NO_RECALL As Long = &H100000

    Private Const SECURITY_ANONYMOUS As Long = 1
    ( SecurityAnonymous << 16 )
    Private Const SECURITY_IDENTIFICATION As Long = 2
    ( SecurityIdentification << 16 )
    Private Const SECURITY_IMPERSONATION As Long = 3
    ( SecurityImpersonation << 16 )
    Private Const SECURITY_DELEGATION As Long = 4
    ( SecurityDelegation << 16 )

    Private Const SECURITY_CONTEXT_TRACKING As Long = &H40000
    Private Const SECURITY_EFFECTIVE_ONLY As Long = &H80000

    Private Const SECURITY_SQOS_PRESENT As Long = &H100000
    Private Const SECURITY_VALID_SQOS_FLAGS As Long = &H1F0000


    Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type


    'Security attributes must be passed as Null - 0
    Private Declare Function CreateFile _
    Lib "kernel32" _
    Alias "CreateFileA" (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Long,
    _
    ByVal dwCreationDisposition As Long,
    _
    ByVal dwFlagsAndAttributes As Long,
    _
    ByVal hTemplateFile As Long) As Long

    'Overlapped must be passed as Null - 0
    Private Declare Function WriteFile _
    Lib "kernel32" (ByVal hFile As Long, _
    ByVal lpBuffer As Long, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As Long) As Long

    Private Declare Function CloseHandle _
    Lib "kernel32" (ByVal hObject As Long) As Long

    Private Declare Sub CopyMemory _
    Lib "kernel32" _
    Alias "RtlMoveMemory" (ByVal Destination As Long, _
    ByVal Source As Long, _
    ByVal Length As Long)


    Private Sub Command1_Click()

    Dim strFile As String
    Dim lngFileHandle As Long

    Dim lngLength As Long
    Dim lngWritten As Long

    Dim lngLocation As Long

    Dim strText As String

    strFile = App.Path & "\woohoo.txt"

    lngFileHandle = CreateFile(strFile, _
    GENERIC_WRITE, _
    0, _
    0, _
    CREATE_NEW, _
    FILE_ATTRIBUTE_TEMPORARY, _
    0)

    strText = "There once was a man in devizes"

    'Get string length in bytes
    lngLength = 2 * Len(strText)

    'Get memory location of string data
    CopyMemory VarPtr(lngLocation), VarPtr(strText), 4

    'And dump awayyyyyy....
    WriteFile lngFileHandle, lngLocation, lngLength, lngWritten, 0

    CloseHandle lngFileHandle

    Kill strFile

    End Sub




  13. #13
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    Option Explicit

    Private Const READ_CONTROL As Long = &H20000
    Private Const DELETE As Long = &H10000
    Private Const WRITE_DAC As Long = &H40000
    Private Const WRITE_OWNER As Long = &H80000
    Private Const SYNCHRONIZE As Long = &H100000
    Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
    Private Const STANDARD_RIGHTS_READ As Long = &H20000
    Private Const STANDARD_RIGHTS_WRITE As Long = &H20000
    Private Const STANDARD_RIGHTS_EXECUTE As Long = &H20000
    Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
    Private Const SPECIFIC_RIGHTS_ALL As Long = &HFFFF
    '
    ' AccessSystemAcl access type
    '
    Private Const ACCESS_SYSTEM_SECURITY As Long = &H1000000
    '
    ' MaximumAllowed access type
    '
    Private Const MAXIMUM_ALLOWED As Long = &H2000000
    '
    ' These are the generic rights.
    '
    Private Const GENERIC_READ As Long = &H80000000
    Private Const GENERIC_WRITE As Long = &H40000000
    Private Const GENERIC_EXECUTE As Long = &H20000000
    Private Const GENERIC_ALL As Long = &H10000000

    Private Const FILE_SHARE_READ As Long = &H1
    Private Const FILE_SHARE_WRITE As Long = &H2
    Private Const FILE_SHARE_DELETE As Long = &H4

    Private Const FILE_ATTRIBUTE_READONLY As Long = &H1
    Private Const FILE_ATTRIBUTE_HIDDEN As Long = &H2
    Private Const FILE_ATTRIBUTE_SYSTEM As Long = &H4
    Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
    Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20
    Private Const FILE_ATTRIBUTE_ENCRYPTED As Long = &H40
    Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
    Private Const FILE_ATTRIBUTE_TEMPORARY As Long = &H100
    Private Const FILE_ATTRIBUTE_SPARSE_FILE As Long = &H200
    Private Const FILE_ATTRIBUTE_REPARSE_POINT As Long = &H400
    Private Const FILE_ATTRIBUTE_COMPRESSED As Long = &H800
    Private Const FILE_ATTRIBUTE_OFFLINE As Long = &H1000
    Private Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED As Long = &H2000

    Private Const CREATE_NEW As Long = 1
    Private Const CREATE_ALWAYS As Long = 2
    Private Const OPEN_EXISTING As Long = 3
    Private Const OPEN_ALWAYS As Long = 4
    Private Const TRUNCATE_EXISTING As Long = 5

    Private Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
    Private Const FILE_FLAG_OVERLAPPED As Long = &H40000000
    Private Const FILE_FLAG_NO_BUFFERING As Long = &H20000000
    Private Const FILE_FLAG_RANDOM_ACCESS As Long = &H10000000
    Private Const FILE_FLAG_SEQUENTIAL_SCAN As Long = &H8000000
    Private Const FILE_FLAG_DELETE_ON_CLOSE As Long = &H4000000
    Private Const FILE_FLAG_BACKUP_SEMANTICS As Long = &H2000000
    Private Const FILE_FLAG_POSIX_SEMANTICS As Long = &H1000000
    Private Const FILE_FLAG_OPEN_REPARSE_POINT As Long = &H200000
    Private Const FILE_FLAG_OPEN_NO_RECALL As Long = &H100000

    Private Const SECURITY_ANONYMOUS As Long = 1
    ( SecurityAnonymous << 16 )
    Private Const SECURITY_IDENTIFICATION As Long = 2
    ( SecurityIdentification << 16 )
    Private Const SECURITY_IMPERSONATION As Long = 3
    ( SecurityImpersonation << 16 )
    Private Const SECURITY_DELEGATION As Long = 4
    ( SecurityDelegation << 16 )

    Private Const SECURITY_CONTEXT_TRACKING As Long = &H40000
    Private Const SECURITY_EFFECTIVE_ONLY As Long = &H80000

    Private Const SECURITY_SQOS_PRESENT As Long = &H100000
    Private Const SECURITY_VALID_SQOS_FLAGS As Long = &H1F0000


    Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type


    'Security attributes must be passed as Null - 0
    Private Declare Function CreateFile _
    Lib "kernel32" _
    Alias "CreateFileA" (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Long,
    _
    ByVal dwCreationDisposition As Long,
    _
    ByVal dwFlagsAndAttributes As Long,
    _
    ByVal hTemplateFile As Long) As Long

    'Overlapped must be passed as Null - 0
    Private Declare Function WriteFile _
    Lib "kernel32" (ByVal hFile As Long, _
    ByVal lpBuffer As Long, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As Long) As Long

    Private Declare Function CloseHandle _
    Lib "kernel32" (ByVal hObject As Long) As Long

    Private Declare Sub CopyMemory _
    Lib "kernel32" _
    Alias "RtlMoveMemory" (ByVal Destination As Long, _
    ByVal Source As Long, _
    ByVal Length As Long)


    Private Sub Command1_Click()

    Dim strFile As String
    Dim lngFileHandle As Long

    Dim lngLength As Long
    Dim lngWritten As Long

    Dim lngLocation As Long

    Dim strText As String

    strFile = App.Path & "\woohoo.txt"

    lngFileHandle = CreateFile(strFile, _
    GENERIC_WRITE, _
    0, _
    0, _
    CREATE_NEW, _
    FILE_ATTRIBUTE_TEMPORARY, _
    0)

    strText = "There once was a man in devizes"

    'Get string length in bytes
    lngLength = 2 * Len(strText)

    'Get memory location of string data
    CopyMemory VarPtr(lngLocation), VarPtr(strText), 4

    'And dump awayyyyyy....
    WriteFile lngFileHandle, lngLocation, lngLength, lngWritten, 0

    CloseHandle lngFileHandle

    Kill strFile

    End Sub




  14. #14
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    Some further comments

    1 - From reading the help text I gather that using FILE_ATTRIBUTE_TEMPORARY
    does not guarantee that the file will not be written to disk, it merely
    means that the operating system will try to avoid writing it to disk. That's
    OK with me.

    2 - It also states that an application should delete the file as long as it
    is no longer needed. But what if the application "forgets" to do this
    (either intentionally or unintentionally). Does that mean the file gets
    written to the disk after all? Could it cause some nasty errors?

    Thanks


    Pino



  15. #15
    Pino Carafa Guest

    Re: Mapping a drive letter to a memory location?

    Some further comments

    1 - From reading the help text I gather that using FILE_ATTRIBUTE_TEMPORARY
    does not guarantee that the file will not be written to disk, it merely
    means that the operating system will try to avoid writing it to disk. That's
    OK with me.

    2 - It also states that an application should delete the file as long as it
    is no longer needed. But what if the application "forgets" to do this
    (either intentionally or unintentionally). Does that mean the file gets
    written to the disk after all? Could it cause some nasty errors?

    Thanks


    Pino



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center