第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

VB API函數(shù)createfile怎么用?

VB API函數(shù)createfile怎么用?

郎朗坤 2019-02-05 11:07:15
我想在D:\haha下創(chuàng)建一個只讀的純文本文件,用createfile來實現(xiàn),但lpSecurityAttributes參數(shù)不知道怎么設(shè)置,高手幫幫啊。最好解釋一下為什么,別讓我換別的,我是在學習怎么用這個。我用過null和byval 0&,都不行。 我要的不是這個函數(shù)的參數(shù)列表……而且這個對我問題沒幫助……
查看完整描述

3 回答

?
慕俠2389804

TA貢獻1719條經(jīng)驗 獲得超6個贊

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

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

Const GENERIC_WRITE = &H40000000
Const CREATE_NEW = 1
Const FILE_ATTRIBUTE_READONLY = &H1

Private Sub Form_Load()
Dim temp As SECURITY_ATTRIBUTES
MsgBox (CreateFile("C:\abc.txt", GENERIC_WRITE, 0, temp, CREATE_NEW, FILE_ATTRIBUTE_READONLY, 0))
End Sub



查看完整回答
反對 回復(fù) 2019-03-18
?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

試著參考下面的代碼


123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102Public Const GENERIC_WRITE = &H40000000      Public Const GENERIC_READ = &H80000000      Const FILE_ATTRIBUTE_NORMAL = &H80      Const CREATE_ALWAYS = 2      Const OPEN_ALWAYS = 4      Const INVALID_HANDLE_VALUE= -1      Const FILE_NAME = "TEST.DAT"     'This can be any file that does not                                       'currently exist.       Type MyType         value As Integer      End Type       Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _         lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _         lpNumberOfBytesRead As LongByVal lpOverlapped As LongAs Long       Private Declare Function CloseHandle Lib "kernel32" ( _        ByVal hObject As LongAs Long       Private Declare Function WriteFile Lib "kernel32" ( _        ByVal hFile As Long, lpBuffer As Any, _        ByVal nNumberOfBytesToWrite As Long, _        lpNumberOfBytesWritten As LongByVal lpOverlapped As LongAs Long       Private Declare Function CreateFile Lib "kernel32" _        Alias "CreateFileA" (ByVal lpFileName As String, _        ByVal dwDesiredAccess As LongByVal dwShareMode As Long, _        ByVal lpSecurityAttributes As Long,  _        ByVal dwCreationDisposition As Long, _        ByVal dwFlagsAndAttributes As LongByVal hTemplateFile As Long) _        As Long       Declare Function FlushFileBuffers Lib "kernel32" ( _        ByVal hFile As LongAs Long       Sub fillArray(anArray() As MyType)         Dim As Integer          For x = 0 To UBound(anArray)            anArray(x).value = x         Next x      End Sub       Sub Main()         Dim fHandle As Integer         Dim T(1000) As MyType            'Define a large array of data         Dim S(1000) As MyType            'Define another large array          fillArray T                      'Fill the array with some values         writearray FILE_NAME, T          'Write the entire array to disk         readArray FILE_NAME, S           'Read into a different array      End Sub       Sub readArray(Fname As String, anArray() As MyType)         Dim fHandle As Long         Dim fSuccess As Long         Dim sTest As String         Dim lBytesRead As Long         Dim BytesToRead As Long          'Get size of data to write         BytesToRead = (UBound(anArray) + 1) * LenB(anArray(0))         'Get a handle to a file Fname.         fHandle = CreateFile(Fname, GENERIC_WRITE Or GENERIC_READ, _                              0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)         'Here you should test to see if you get a file handle or not.         'CreateFile returns INVALID_HANDLE_VALUE if it fails.         If fhandle <> INVALID_HANDLE_VALUE Then            fSuccess = ReadFile(fHandle, anArray(LBound(anArray)), _                                BytesToRead, lBytesRead, 0)            'ReadFile returns a non-zero value if it is successful.            'Now you just close the file.            fSuccess = CloseHandle(fHandle)         End If      End Sub       Sub writearray(Fname As String, anArray() As MyType)         Dim fHandle As Long         Dim fSuccess As Long         Dim sTest As String         Dim lBytesWritten As Long         Dim BytesToWrite As Long         'Get the length of data to write         BytesToWrite = (UBound(anArray) + 1) * LenB(anArray(0))         'Get a handle to a file Fname.         fHandle = CreateFile(Fname, GENERIC_WRITE Or GENERIC_READ, _                              0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)         'Here you should test to see if you get a file handle or not.         'CreateFile returns INVALID_HANDLE_VALUE if it fails.         If fhandle <> INVALID_HANDLE_VALUE Then            fSuccess = WriteFile(fHandle, anArray(LBound(anArray)), _                                 BytesToWrite, lBytesWritten, 0)            'Check to see if you were successful writing the data            If fSuccess <> 0 Then               'Flush the file buffers to force writing of the data.               fSuccess = FlushFileBuffers(fHandle)               'Close the file.               fSuccess = CloseHandle(fHandle)            End If         End If      End Sub



查看完整回答
反對 回復(fù) 2019-03-18
  • 3 回答
  • 0 關(guān)注
  • 866 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號