Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2005, 08:56
Warren
 
Posts: n/a
help with visual basic and API

I'm creating a program through VB 6 that monitors file access (aka if someone's been messing with your stuff). Basically it involves choosing the files to be monitored, obtaining properties such as file size, last modified, last accessed, etc. and running that information through the md5 algorithm to create a default hash. The properties will be hashed every x minutes and compared to the default hashes, and if any differences occur a message box/email/phone message will be sent to the computer's administrator. I tried to use API calls but I'm lost. Here is what I have so far. It seems I can't run those calls even though I put in the code...its really frustrating.

Code:
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Public Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Public Declare Function GetFileTime Lib "kernel32.dll" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long

Private Declare Function MakeMD5Digest _
Lib "di_MD5DLL.dll" _
(ByVal sData As String, ByVal sDigest As String) As Long

Public Function MD5HexDigest(sData As String) As String
Dim iRet As Long
Dim sDigest As String
' Set sDigest to be 32 chars
sDigest = String(32, " ")
iRet = MakeMD5Digest(sData, sDigest)
MD5HexDigest = Trim(sDigest)
End Function


Private Sub cmdRun_Click()

Dim FileInfo As String
Dim StandardComp As String
Dim Size As String
Dim lastacc As String

Size = GetFileSize(txtFolder.Text)
lastacc = GetFileTime(txtFolder.Text)
FileInfo = Size + lastacc
StandardComp = MD5HexDigest(FileInfo)

End Sub

Private Sub Command1_Click()
listFolders.AddItem txtFolder.Text
End Sub
'thats just to add file names to a list box.
I just want to make the md5 compare itself to StandardComp every x minutes and alert if they arent equal.

Help would be great from anyone.
Reply With Quote
  #2  
Old 08-25-2005, 13:03
TheMadGuy
 
Posts: n/a
Quote:
Originally Posted by Warren
I tried to use API calls but I'm lost. Here is what I have so far.
Hi!

can you be a bit more specific, what does happen when you try to run this code?

There is a hell lot of what you can do wrong when calling a dll from vb, and the calling method highly differs depending on how the dll export was defined.

Besides that you declared GetFileSize and GetFileTime but the way you call does not nearly match their declaration and you will also need these api's if you want to complete your task:
Code:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Hope this gets you startet but i need a bit more info to really help ya!

Greetnx

The Mad Guy
Reply With Quote
  #3  
Old 08-25-2005, 16:32
Mkz Mkz is offline
Friend
 
Join Date: Jan 2002
Posts: 98
Rept. Given: 0
Rept. Rcvd 2 Times in 2 Posts
Thanks Given: 5
Thanks Rcvd at 25 Times in 17 Posts
Mkz Reputation: 2
You really should take a look at the documentation for the API's you're using

If you check GetFileSize on MSDN (hxxp://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfilesize.asp), you'll see it takes two arguments:
- hFile, a handle to a file that should be obtained from CreateFile
- a pointer to the high-order dword of the size
It will return the low-order dword with the size, or an error code.

The way you're using:
Quote:
Size = GetFileSize(txtFolder.Text)
Size is a String, but it's ok since the result of GetFileSize, which is a Long, will be automatically converted to String.
But you're passing it a String!!! You should pass a handle from CreateFile, and a 2nd Long variable, to receive the high-order dword.

For GetFileTime you have a similar problem, you need to check the API docs to see you must pass the 3 structures to get the 3 filetimes, and not use the function return value as you currently do. For this function, the return value merely indicates if it succeeded or not.

Finally, don't forget to "CloseHandle" after you don't need it any more, as is probably explained in the "CreateFile" docs.
Reply With Quote
  #4  
Old 08-25-2005, 17:03
dj-siba's Avatar
dj-siba dj-siba is offline
Musician Member
 
Join Date: Jun 2003
Location: Outside the dot
Posts: 324
Rept. Given: 34
Rept. Rcvd 43 Times in 21 Posts
Thanks Given: 56
Thanks Rcvd at 159 Times in 43 Posts
dj-siba Reputation: 42
i have a DLL created with Delphi,
Code:
procedure MyProc(MyPtr: pointer);
how do i Call in VB 6 ?
Code:
Private Declare Sub MyProc Lib "mylib.dll" (MyPtr as ???)
Regards

Last edited by dj-siba; 08-25-2005 at 17:29.
Reply With Quote
  #5  
Old 08-25-2005, 17:09
TQN TQN is offline
VIP
 
Join Date: Apr 2003
Location: Vietnam
Posts: 343
Rept. Given: 142
Rept. Rcvd 20 Times in 12 Posts
Thanks Given: 169
Thanks Rcvd at 130 Times in 43 Posts
TQN Reputation: 20
You can declare: (ByVal MyPtr As Long)
Reply With Quote
  #6  
Old 08-26-2005, 13:48
TheMadGuy
 
Posts: n/a
And depending on what you pass from vb you might need to use VarPtr or StrPtr for passing your argument to your .dll then.

Greetnx

The Mad Guy
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] Visual Basic dll protection Maltese General Discussion 12 08-13-2005 19:05


All times are GMT +8. The time now is 18:05.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )