Announcement

Collapse
No announcement yet.

STRPTR functionality wish

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

  • STRPTR functionality wish

    Is it possible to make STRPTR work on string equates? Something like:
    Code:
    $a = "Aldo Cavini"
    b  = STRPTR( $a )
    This could be useful, for instance, on registering a Window Class. The only way I know to assign the lpszClassName value is via a string or asciiz variable. Am I wrong?

    Aldo

    ------------------
    Rgds, Aldo

  • #2
    I think not but:

    Control Add "" & $HELLO works fine..

    ------------------
    http://www.hellobasic.com
    hellobasic

    Comment


    • #3
      It is not possible to obtain a VARPTR or a STRPTR to a String Equate. Think of them as mini-macro's - they are "used" during compile-time, not run-time.

      However, depending on how the API you are calling is declared, you may be able to pass the string equate BYCOPY (which is what Edwin's example above is doing).
      Code:
      ' These all pass bycopy:
      CALL apifunction(BYCOPY $MyString) ' Explicit BYCOPY
      CALL apifunction($MyString + "")   ' Expressions passed BYCOPY
      CALL apifunction(($MyString))      ' Parentheses force evaluation as an expression, hence BYCOPY
      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Edwin, Lance,

        thanks for the replies. Of course I do know how to pass a string by value. What I would like do is the following:
        Code:
        LOCAL wc as WndClassEx 
          ...
          wc.lpszClassName = VARPTR( AsciizVariable )
          ...
          RegisterClassEx wc
        or
        Code:
          wc.lpszClassName = STRPTR( StringVariable )
        without having to use a variable. I mean:
        Code:
          wc.lpszClassName = VARPTR( $StringEquate )
        I thought, since the string equate value is stored somewhere inside the executable file, its address could be retreived at run-time. Never mind...


        ------------------
        Rgds, Aldo

        Comment


        • #5
          posted http://www.powerbasic.com/support/pb...ad.php?t=23155

          ------------------
          Rgds, Aldo

          Comment


          • #6
            Cute... using a function means you can pass string equates BYCOPY/BYVAL and register your window.

            I'm sure there are plenty of places this approach could be used, except when you want the code in line.

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

            Comment


            • #7
              Hi Aldo,

              I use the following inc-file:
              Code:
              #if not %def(%TEXT_INC)
              %TEXT_INC = 1
               
              %TEXT = 1
              %FreeTEXT = 2
               
              global TEXTMemory() as string   ' Would be better as static inside MainTEXTfunc. Not safe in current version of PB.
              function MainTEXTfunc(byval func_id as long, byval s as string) as dword
               
                  static n as long
                   
                  select case func_id
                  case %TEXT
                      redim preserve TEXTMemory(n)
                      TEXTMemory(n) = s
                      incr n
                      function = strptr(TEXTMemory(n-1)) : exit function
               
                  case %FreeTEXT
                      n = 0
                      redim TEXTMemory(0)
                   
                  end select
               
              end function
               
              function TEXT(byval s as string) as dword
                  function = MainTEXTfunc(%TEXT, s)
              end function
               
              sub FreeTEXT()
                  MainTEXTfunc %FreeTEXT, ""
              end sub
               
              #endif '%TEXT_INC
              If you use this as header-file, you can use any of the following
              alternatives:
              Code:
                  wc.lpszClassName = TEXT( AsciizVariable )
                  wc.lpszClassName = TEXT( StringVariable )
                  wc.lpszClassName = TEXT( $StringEquate )
                  wc.lpszClassName = TEXT( "MyClassName" )
              Regards
              Peter

              P.S.

              If you like you can free memory using FreeTEXT (you dont have to)

              ------------------
              [email protected]
              [email protected]
              www.dreammodel.dk

              Comment


              • #8
                Peter,

                good idea. I also had the idea to assign the string equate to a static/global string, but didn't thought about using an array

                Aldo

                ------------------
                Rgds, Aldo

                Comment

                Working...
                X