乙個API方式訪問日誌檔案的模組

2021-05-23 08:23:46 字數 1765 閱讀 7090

declare function createfile lib "kernel32" alias "createfilea" (byval lpfilename as string, byval dwdesiredaccess as long, byval dwsharemode as long, byval lpsecurityattributes as any, byval dwcreationdisposition as long, byval dwflagsandattributes as long, byval htemplatefile as long) as long

declare function setfilepointer lib "kernel32" (byval hfile as long, byval ldistancetomove as long, lpdistancetomovehigh as long, byval dwmovemethod as long) as long

declare function flushfilebuffers lib "kernel32" (byval hfile as long) as long

declare function closehandle lib "kernel32" (byval hobject as long) as long

if (len(dir(lpfilename))) then

flen = filelen(lpfilename)

end if

'open the log file, create as necessary

dim hlogfile as long

hlogfile = createfile(lpfilename, generic_write, file_share_read, byval 0&, _

iif(len(dir(lpfilename)), open_existing, create_new), _

file_attribute_normal, 0&)

'ensure the log file was opened properly

'    

if (hlogfile = invalid_handle_value) then exit function

'move file pointer to end of file if fil

'     e was not created

if (flen <> 0) then

if (setfilepointer(hlogfile, flen, byval 0&, file_begin) = &hffffffff) then

'exit sub if the pointer did not set cor

'     rectly

closehandle (hlogfile)

exit function

end if

end if

'convert the source string to a byte arr

'     ay for use with writefile

dim ltemp as long

redim temparray(0 to len(smessage) - 1) as byte

for ltemp = 1 to len(smessage)

temparray(ltemp - 1) = asc(mid$(smessage, ltemp, 1))

next

'write the string to the log file

乙個操作日誌檔案的類

在軟體中常用到日誌檔案,這是我在專案中用到的乙個操作日誌檔案的類。imports system imports system.io public class classlogfile inherits system.object public shared logfilename as string...

乙個簡易日誌類,基於win32API

度娘並結合自己的需求實現了乙個基於win32api的日誌類,可用於mfc,只是簡單實現,可能還有些潛在的bug,這裡算是記錄下學習成果。目標是方便輸出除錯日誌,並且只在debug編譯,可以支援可變引數的日誌資訊。用到了win32api,經過適當的修改應該也可以用於標準庫。ifndef slog h ...

乙個API攔截的例子

閒來無事,做乙個api攔截的簡單程式,目標是攔截exploer.exe的createprocess.當開啟桌面程式時,執行自定義的 首先需要確認的是,explorer.exe建立程序是用了什麼函式,建立程序自然想到用createprocess createprocessa,createprocess...