Announcement

Collapse
No announcement yet.

Data Type question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    Simple.

    Create a fixed-length string of the longest structure size, and pass the address of the string to the API.

    Next, create two UDT pointers, and point them to the string, then use the appropriate pointer to manipluate the data.

    If you need to initialize a structure member with the structure size first (which some API's need), use the appropriate pointer to set the value.

    ie:
    Code:
    TYPE sometype1
    ...
    END TYPE
    TYPE sometype2
    ...
    END TYPE
     
    ... 
     
    DIM z AS STRING * <the larger size of sometype1 and sometype2>
    DIM p1 sometype1 PTR
    p1 = VARPTR(z)
    DIM p2 sometype2 PTR
    p2 = VARPTR(z)
     
    CALL someapifunction(BYVAL VARPTR(z),...)
     
    IF condition THEN
      @p1.xxx = ...
    ELSE
      @p2.xxx = ...
    ENDIF
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    PS, we all 3 replied at the same time!

    I'll post the entire source to this tomorrow evening when I get it done, it's coming along VERY nicely!
    This will be a MUST have for everyone, a new GetWindowsVersion, Microsoft style and very tight so far in the port to PB...


    Scott


    ------------------
    Scott

    Leave a comment:


  • Scott Turchin
    replied
    Ah, OK IT's the union of potato's and banana's!! LOL...

    In all seriousness here's what I'm trying to do, and now I know how I have to go about it, a Union may not work here but for future use perhaps


    Code:
    The new OSINFO!!!
    '
    '
    '
    %ERROR_OLD_WIN_VERSION = 0
    
    Type OSVERSIONINFOEX
      dwOSVersionInfoSize As Dword
      dwMajorVersion As Dword
      dwMinorVersion As Dword
      dwBuildNumber As Dword
      dwPlatformId As Dword
      szCSDVersion As Asciiz * 128
      wServicePackMajor As Dword  'Word?
      wServicePackMinor As Dword  'Word?
      wSuiteMask As Dword    'Word?
      wProductType As Byte
      wReserved As Byte
    End Type  
    
    
    '
    osviex.dwOsVersionInfoSize = SizeOf(osviex)
    bOsVersionInfoEx = GetVersionEx(osviex)
    
    If bOsVersionInfoEx = %ERROR_OLD_WIN_VERSION Then 'It failed
       lResult = GetVersionEx(osvi)
    End If
    ------------------
    Scott

    Leave a comment:


  • Lance Edmonds
    replied
    Bern, we both responded at almost the same time! SNAP!

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Bern Ertl
    replied
    Scott,

    I'm not sure if it is possible, but would it work for you to make
    a UNION of the two types with an identifier?

    Ie.:

    Code:
    TYPE OrigType1
    .....
    END TYPE
    
    TYPE OrigType2
    .....
    END TYPE
    
    UNION OrigTypes
      FirstType AS OrigType1
      SecondType AS OrigType2
    END UNION
    
    TYPE NewType
      Active AS LONG 'Just a binary flag
      Data AS OrigTypes
    END TYPE
    You can check the .Active field to determine which of the
    unioned types to access.....



    ------------------
    Bernard Ertl

    Leave a comment:


  • Lance Edmonds
    replied
    You cannot do this directly, since the UDT must be established at compile time (or more accurately, when used to define a scalar variable, the DIM statement works as a scanned statement, not an executable statement). That is, the following is not valid:
    Code:
    IF condition THEN
      DIM a AS T1Type
    ELSE
      DIM a AS T2Type
    END IF
    So how do you do it? Simple: The solution is to create a UNION of the two TYPEs, or a UNION containing pointers to the real UDT variables.
    Code:
    UNION Matter
      Potato AS VEGTYPE
      Banana AS FRUITTYPE
    END UNION
    ..
    DIM a AS MATTER
    a.Potato.xxx = ...
    a.Banana.xxx = ...
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    started a topic Data Type question

    Data Type question

    I have a TYPE and I dim it as such perhaps:

    mytype as TYPEA

    Now, I test a function with this mytype and if the function fails I want to have mytype dimmed as TYPEB


    Can that be done?


    Thanks,
    If so, got a nice lil' suprise to go in the source code forum, otherwise it will be tomorrow..


    Scott

    ------------------
    Scott
Working...
X