You are not logged in.

axtens

Trainee

  • "axtens" is male
  • "axtens" started this thread

Posts: 37

Date of registration: Mar 16th 2009

Location: Perth, WA, Australia

Occupation: Software/Test Engineer

Hobbies: be a husband and a dad, play ukulele, sing

  • Send private message

1

Monday, October 12th 2009, 3:49pm

Can't quite figure out VarPtr

This is a beginning on mplementing the Dir() functions as per OlimilO's code suggestion. VarPtr is also used.

Problem now is working out how to pass a pointer to a string to a *W function.

Please tell me there's another way of getting at the Win32 file attributes (particularly the archive bit).

Regards,
Bruce.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Option Explicit

Private WinAPI Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesW" ( _ 
	 ByVal lpFileName As Long) As Long

Private fDir As java#io#File
Private iDirIndex As Integer
Private aDirFiles() As java#io#File

Public Function Dir() As String
   Dim i As Long
   Dim s As String
   Dim a As Long
   
   If iDirIndex <= Ubound(aDirFiles) Then
  	s = aDirFiles(iDirIndex).getPath.toString 'getName
  	i = varptr.CreateVar("foo","String",Len(s))
  	a = GetFileAttributes(i)
  	Debug.Print a
  	Dir = s
  	iDirIndex = iDirIndex + 1
  	varptr.DestroyVar("foo")
   Else
  	iDirIndex = 0
  	Dir = vbNullString
   End If
End Function

Public Function Dir(sPathName As String) As String
   fDir = New java#io#File(sPathName)
   Dir = fDir.getPath
   Dim i As Long
   Dim attr As Long
   i = varptr.CreateVar( "foo","String",Len(sPathName))
   Debug.Print i
   varptr.SetStringVar("foo",sPathName)
   attr = GetFileAttributes(i)
   Debug.Print attr
   aDirFiles = fDir.listFiles
   Dir = aDirFiles(0).getPath.toString
   iDirIndex = iDirIndex + 1
   varptr.DestroyVar("foo")
End Function

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Thursday, October 15th 2009, 12:15pm

Hi Bruce,

Quoted

Problem now is working out how to pass a pointer to a string to a *W function.

I'm sure there is a way to do this... but...

Quoted

Please tell me there's another way of getting at the Win32 file attributes (particularly the archive bit).

... of course there is another way!

For the FileAttributes you could also use the FileSystemObject over the JACOB.

The FileSystemObject can be accessed through


MySQL queries

1
2
3
Library Scripting
    C:\WINDOWS\system32\scrrun.dll
    Microsoft Scripting Runtime

so make sure you have this dll in the system installed. (normally every VB-developer has it)



For the file attributes you could use this class FileSystemObject:

Jabaco Source

1
2
3
4
5
6
7
8
9
Option Explicit
Dim myBase As Dispatch
Public Sub FileSystemObject()
   myBase = New ActiveXComponent("Scripting.FileSystemObject").getObject()
End Sub
Public Property Get FileAttributes(path As String) As VBA#VbFileAttribute
   Dim aFile As Dispatch = Dispatch.call(myBase, "GetFile", path).getDispatch
   FileAttributes = New VBA#VbFileAttribute(Dispatch.call(aFile, "Attributes").getInt)
End Property


using the class:

Jabaco Source

1
2
3
4
5
6
7
8
9
Option Explicit
Dim myFileSO As New FileSystemObject
Public Sub Command1_Click()
   
   Dim a As VBA#VbFileAttribute = myFileSO.FileAttributes("C:\Test.txt")
   
   MsgBox a.getName & ": " & CStr(a.intValue)
   
End Sub




regards

OlimilO
remarks:
in the next version of the Jabaco framework the getName-function of an enum-value will also deliver all names as flags set in a flag-enum. (so is the VBFileAttributes-enum)

axtens

Trainee

  • "axtens" is male
  • "axtens" started this thread

Posts: 37

Date of registration: Mar 16th 2009

Location: Perth, WA, Australia

Occupation: Software/Test Engineer

Hobbies: be a husband and a dad, play ukulele, sing

  • Send private message

3

Friday, October 16th 2009, 3:30am

in the next version of the Jabaco framework the getName-function of an enum-value will also deliver all names as flags set in a flag-enum. (so is the VBFileAttributes-enum)
Marvellous idea! Wonderful! When? ;)

axtens

Trainee

  • "axtens" is male
  • "axtens" started this thread

Posts: 37

Date of registration: Mar 16th 2009

Location: Perth, WA, Australia

Occupation: Software/Test Engineer

Hobbies: be a husband and a dad, play ukulele, sing

  • Send private message

4

Friday, October 16th 2009, 3:57am

VBA#VbFileAttribute, sad to say, isn't in my copy of the Framework, which is the 08/08/2009 version. Is there a better one?

Bruce.

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

5

Friday, October 16th 2009, 7:46am

Quoted

sad to say, isn't in my copy
*cringe* wo gehobelt wird da fallen Späne -> it's under construction

Quoted

Is there a better one

look,

it really doesn't matter what Enum you use, it's important to have the right values. You have the following possibilities:
* maybe goto VB6 and copy alle the values out of the objectexplorer
* maybe goto the Jabaco-Framework-trunk and copy it out of the sourcecodes:
http://code.google.com/p/jabacoframework…FileSystem.jsrc

* maybe copy the Enum with the .net-reflector out of the .net-Framework just to be aware to have it up to date and complete
compare it:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Enum FileAttributes
   ' Fields
   ReadOnly     = &H1
   Hidden       = &H2
   System       = &H4
   '?
   Directory    = &H10
   Archive      = &H20
   Device       = &H40
   Normal       = &H80
   Temporary    = &H100
   SparseFile   = &H200
   ReparsePoint = &H400
   Compressed   = &H800
   Offline      = &H1000
   NotContentIndexed = &H2000
   Encrypted    = &H4000
End Enum
Enum VbFileAttribute
   vbNormal = &H0
   vbReadOnly = &H1
   vbHidden = &H2
   vbSystem = &H4
   vbVolume = &H8
   vbDirectory = &H10
   vbArchive = &H20
   vbAlias = &H40
End Enum


OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

6

Friday, October 16th 2009, 8:58am

Hi,
what happens during a call to JaCoB?
Is there a full process lifecycle for every call?

My understanding is that there is currently no Java way to extract the file attributes including the Archive bit.
The forthcoming Java 7 will have a function in java.nio to access such attributes.
My congratulations to Bruce for his talent to reach the limits of Jabaco and Java 8)

Cheers

A1880

Rate this thread
WoltLab Burning Board