You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Saturday, May 23rd 2009, 2:27pm

Size of a structure

Hello community, hello Manuel,
another question about structures:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Private Type test
  test1 As String
  test2 As Long
  test3 As Boolean
End Type

Public Sub Test_Click()

   Dim hugo As test
   
   java#lang#System.out.println Len(hugo)
   
   hugo.test1 = "Test"
   hugo.test2 = 42
   hugo.test3 = True

End Sub


I get an error at the line java#lang#System.out.println Len(hugo), "Momentan ist eine automatische Konvertierung von 'test' nach 'String' nicht möglich". Is there another way to calculate the size of structure?

Thanks and cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Saturday, May 23rd 2009, 5:52pm

Hi Stefan,

you always have to keep in mind that the big brother behind Jabaco is Java, and Java, just like .NET, is a managed pointerless language.
Normally you do not have to know the size of a structure, because normally you do not have to deal with memory.

The thing in VB called UD-Type is in Jabaco more like a private class.
So the main problem is: can anybody say that the variables are really in consecutive order?
because if not, knowing the sizes is no useful information.
But of course you could sum together the single variable sizes if you have information about the size of a single variable.


AFAIR there is no information about the size of primitive datatypes in Jabaco.

[edit]

ah yes there is!!

Informations about the size of primitive datatypes in Jabaco can be found here:

Data Types and Operators

http://www.jabaco.org/wiki/Data_Types_and_Operators
[/edit]


[delete]

so we could guess:

[edit]

no we do not have to guess!

[/edit]

1 byte: Byte
2 byte: (is there a) Short?
4 byte: Integer, Long (Int32), Single
8 byte: Double, what else?
what about Date?
what about the Variant Type?
and String, is it just like in Classic VB?

[/delete :P ]


the question is: for what does one need to know about the sizes in memory?

1. Answer: writing information from a UDType-variable to a file

in VB-Classic if you want to write UDType-variables to a file, there are two very powerful commands

the Get and Put commands that let you write a UD-Type variable to disk in one single line:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
'VB6-Code 
Public Type MyType 
Var1 As Integer 
Var2 As Integer 
Var3 As Long 
Var4 As String 
End Type 

Public Sub WriteMyType(MyType As MyType, FNr As Integer) 
Put FNr, , MyType 
End Type 
Public Sub ReadMyType(MyType As MyType, FNr As Integer) 
Get FNr, , MyType 
End Type


But... you know, you also could read/write each single varaible of the UD-Type one after the other, and you get the same result:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
Public Sub WriteMyType(MyType As MyType, FNr As Integer) 
Put FNr, , MyType.Var1 
Put FNr, , MyType.Var2 
Put FNr, , MyType.Var3 
Put FNr, , MyType.Var4 
End Type 
Public Sub ReadMyType(MyType As MyType, FNr As Integer) 
Get FNr, , MyType.Var1 
Get FNr, , MyType.Var2 
Get FNr, , MyType.Var3 
Get FNr, , MyType.Var4 
End Type


the only difference is: the second code is longer
what is your aim for knowing the size in memory?
:) as long as we have your VarPtr-dll we have a possible way around some pointer things.

what about making UDType-variables possible in the VarPtr.dll?
what about getting String representations of variables in the VarPtr.dll?

greetings
OlimilO

This post has been edited 1 times, last edit by "OlimilO" (Jun 4th 2009, 9:34am)


  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

3

Saturday, May 23rd 2009, 10:38pm

Size of a structure and VarPtr

Hello Oliver,
thanks for your explanation.

Most of the structures of the WinAPI use the size of the structure. Here is a example for the Windows Help API:

Source code

1
2
3
4
5
6
7
8
9
10
Private Type HH_FTS_QUERY
  cbStruct As Long '< Here is the size of the structure
  fUniCodeStrings As Long
  pszSearchQuery As String
  iProximity As Long
  fStemmedSearch As Long
  fTitleOnly As Long
  fExecute As Long
  pszWindow As String
End Type


To use user defined types I extended the VarPtr.dll - thanks for the hint, look at the following code:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'-Begin------------------------------------------------------------

  '-External functions---------------------------------------------
    Private WinAPI Function !HtmlHelp Lib "hhctrl.ocx" _
      Alias "HtmlHelpA" (ByVal hwndCaller As Long, _
      ByVal pszFile As String, ByVal uCommand As Long, _
      ByVal dwData As Long) As Long

  '-Constants------------------------------------------------------
    Private Const HH_DISPLAY_TOPIC As Long =&H0
    Private Const HH_DISPLAY_TOC As Long = &H1
    Private Const HH_DISPLAY_INDEX As Long = &H2
    Private Const HH_DISPLAY_SEARCH As Long = &H3
    Private Const HH_CLOSE_ALL As Long = &H12

  '-Global variables-----------------------------------------------
    Dim VarPtr As New VarPtr()
    
    Dim FileName As String = "c:\\windows\\help\\wmplayer.chm"

  '-ButtonClick----------------------------------------------------
    Public Sub Command1_Click()

      !HtmlHelp 0, FileName, HH_DISPLAY_TOPIC, 0

      Dim HH_FTS_QUERY As Long
      HH_FTS_QUERY = VarPtr.CreateVar("HH_FTS_QUERY", "Array", 32)

      Dim pszSearchQeury As Long
      pszSearchQuery = VarPtr.CreateVar("pszSearchQuery", "String", 8)
      VarPtr.SetStringVar "pszSearchQuery", "foo"
   
      Dim pszWindow As Long
      pszWindow = VarPtr.CreateVar("pszWindow", "String", 4)
      VarPtr.SetStringVar "pszWindow", ""
   
      VarPtr.SetArrayLong "HH_FTS_QUERY",  0, 32  'cbStruct
      VarPtr.SetArrayLong "HH_FTS_QUERY",  4, 1   'fUniCodeStrings
      VarPtr.SetArrayLong "HH_FTS_QUERY", 8, pszSearchQuery
      VarPtr.SetArrayLong "HH_FTS_QUERY", 12, 0   'iProximity
      VarPtr.SetArrayLong "HH_FTS_QUERY", 16, 0   'fStemmedSearch
      VarPtr.SetArrayLong "HH_FTS_QUERY", 20, 1   'fTitleOnly
      VarPtr.SetArrayLong "HH_FTS_QUERY", 24, 1   'fExecute
      VarPtr.SetArrayLong "HH_FTS_QUERY", 28, pszWindow
      
      !HtmlHelp 0, FileName, HH_DISPLAY_SEARCH, HH_FTS_QUERY
      
      VarPtr.DestroyVar "pszWindow"
      VarPtr.DestroyVar "pszSearchQuery"
      VarPtr.DestroyVar "HH_FTS_QUERY"
   
    End Sub
  '-Button2Click---------------------------------------------------
    Public Sub Command2_Click()
      !HtmlHelp 0, "", HH_CLOSE_ALL, 0
    End Sub
    
'-End--------------------------------------------------------------


It is the same as this in VB:

Source code

1
2
3
4
5
6
7
8
9
10
Dim strSearch As HH_FTS_QUERY
strSearch.cbStruct = 32
strSearch.fUniCodeStrings = 1&
strSearch.pszSearchQuery = "foo"
strSearch.iProximity = 0&
strSearch.fStemmedSearch = 0&
strSearch.fTitleOnly = 1&
strSearch.fExecute = 1&
strSearch.pszWindow = ""
!HtmlHelp 0, FileName, HH_DISPLAY_SEARCH, strSearch


Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Sunday, May 24th 2009, 12:52pm

It's Cool Man :thumbup:

greetings,

OlimilO

Rate this thread
WoltLab Burning Board