| | | Forum Newbie
       
Group: Forum Members Last Login: 3/28/2005 2:52:00 PM Posts: 5, Visits: 1 |
| I have a bunch of questions but will list a few. I referenced the Applebaum book and looked at examples, but some of the basics confound me. I'm trying to write VB6 code to interface with a "C/C++" DLL. In a VB6 module1.bas I have the following: Public Type STA_PROPS cbSize As Long STA_DPROP_DEVADDR As String '- Device Address 08 STA_DPROP_GATEWAY As String '- Gateway Address 10 STA_DPROP_NETMASK As String '- Network Mask 20 STA_DPROP_MASK As String 'Mask of used props 38 Which are chosen from: ' STA_DPROP_DATETIME '0x00000001 ///< Date/Time ' STA_DPROP_DEVID '0x00000002 ///< Device ID ' STA_DPROP_ALIAS '0x00000004 ///< Alias ' STA_DPROP_LOCATION '0x00000004 ///< Location ID (same as Alias - compatibility) ' STA_DPROP_DEVADDR '0x00000008 ///< Device Address ' STA_DPROP_GATEWAY '0x00000010 ///< Gateway Address ' STA_DPROP_NETMASK '0x00000020 ///< Network Mask ETC ' STA_DPROP_MASK '0x00FFFFFF ///< Mask of Used DevProp flags In my VB Form; Is the DPRPOP_MASK calculated correctly ? and would it be specified as Dim DPROP_MASK As String, or as long DPROP_MASK = &H38, or "0x00000038" or what How would I DIM the string mystring = "abcdefghij" Dim mystring As string * 10 or mystring * &HA or mystring How do I calculate the cbsize (Size of the structure) what if the structure had 2 LONG variables, and the above string, how would I calculate the size? Thanks for any help? |
| | | | 
Junior Member
       
Group: Forum Members Last Login: 12/14/2007 6:54:10 PM Posts: 18, Visits: 7 |
| Use variable = Len(Structure)
 Spsp_1981: spsp_1981[remove.this]@tutopia.com
|
| | | | Forum Newbie
       
Group: Forum Members Last Login: 3/28/2005 2:52:00 PM Posts: 5, Visits: 1 |
| I don't understand the response. How can variable = Len(Structure) if structure isn't defined yet. The SIZE of the structure is part of the definition of the structure. Or am I really missing something simple here? |
| | | | 
Junior Member
       
Group: Forum Members Last Login: 12/14/2007 6:54:10 PM Posts: 18, Visits: 7 |
| First of all I want to state that for structure I understood UDT as commonly called between VB programmers. Tell me if I'm wrong because my mother language is not English and sometimes I misunderstand some concepts. When reading about the Windows' API, I found a lot of functions that require an structure as a parameter (SHELL_NOTIFYICON for example) and a commonly used coding standard in the API requieres the structure to have a field where to store its size, so if a function has multiple versions using different structures, the function can know from the size of the structure, which version to implement. So that, when you want to store the mentioned size in the field, you use Len() which returns the size of it from the declaration. Example: Public Type EXAMPLE_UDT Name As String Age As Integer Height As Long End Type 'EXAMPLE_UDT Each field has a predefined Data-Type which has a predefined size given by VB itself. So when you write: Len(EXAMPLE_UDT) what VB does is look the UDT's fields' data types and calculates the amount of memory it uses, and thats the information the function needs to know. Hope you understand what I hardly tried to explain. I can't remember exactly where I read about it but I believe it must have been in Bruce McKinney's HardCore Visual Basic book which comes with Visual Studio 6 MDSN
 Spsp_1981: spsp_1981[remove.this]@tutopia.com
|
| | | | Forum Newbie
       
Group: Forum Members Last Login: 3/28/2005 2:52:00 PM Posts: 5, Visits: 1 |
| Here's my problem. Your example is: Public Type EXAMPLE_UDT Name As String Age As Integer Height As Long End Type 'EXAMPLE_UDT But my DLL requires a change to your example Public Type EXAMPLE_UDT ExampleSize As Long Name As String Age As Integer Height As Long End Type ‘EXAMPLE_UDT The size is part of the definition. And I think I could figure out the ExampleSize, since I know each LONG is 8 Bytes, but I don't know the size of the Name String. In VB you just declare Name as String, but in "C" you have to be more specific, but I can't find an example. |
| | | | 
Junior Member
       
Group: Forum Members Last Login: 12/14/2007 6:54:10 PM Posts: 18, Visits: 7 |
| READ the text on TOP and BELOW the piece of code I wrote in my previous answer, it took me quite a long time (on a dial-up connection), so PLEASE!!!
Public Type EXAMPLE_UDT
ExampleSize As Long
Name As String
Age As Integer
Height As Long
End Type ‘EXAMPLE_UDT
Dim MyData As EXAMPLE_UDT
With MyData
.Name = "Spsp_1981"
.Age = 22
.Height = 1.82
.ExampleSize = Len(MyData)
End With ‘MyData
 Spsp_1981: spsp_1981[remove.this]@tutopia.com
|
| | | | Forum Newbie
       
Group: Forum Members Last Login: 3/28/2005 2:52:00 PM Posts: 5, Visits: 1 |
| That example cleared it up. I tried it, and the routine came up with the number I expected. I think that also cleared up another question I had. Apparently, the string size is not related to the size of the string, it is just a pointer to the string, so it has the same length as any other LONG. Thanks for the help |
| | | | 
Junior Member
       
Group: Forum Members Last Login: 12/14/2007 6:54:10 PM Posts: 18, Visits: 7 |
| Your welcome
 Spsp_1981: spsp_1981[remove.this]@tutopia.com
|
| |
|
|