curious behavior with StringValuePtr()

Discussion in 'Ruby' started by Daniel Berger, Jul 2, 2004.

  1. Hi all,

    Ruby 1.8.2 RC2
    Windows 2000
    VC++ 6.0

    I was going to update all of my STR2CSTR() calls to StringValuePtr()
    for one of my packages, when I noticed that I can't seem to pass it a
    method without it raising a fuss.

    This is the old snippet, which worked perfectly fine.

    lpSourceName = (LPCTSTR)STR2CSTR(rb_iv_get(self,"@source"));

    This snippet fails, however:

    lpSourceName = (LPCTSTR)StringValuePtr(rb_iv_get(self,"@source"));

    I get this error:

    eventlog.c(554) : error C2102: '&' requires l-value
    eventlog.c(554) : error C2198: 'rb_string_value_ptr' : too few actual
    parameters

    This behavior does not occur if I pass a plain value to StringValuePtr
    instead of passing a function. And no, the casting is not the issue
    (I tried a snippet without it).

    Any ideas? Thanks.

    Dan
    Daniel Berger, Jul 2, 2004
    #1
    1. Advertising

  2. --- Daniel Berger <> wrote:
    >
    > lpSourceName = (LPCTSTR)StringValuePtr(rb_iv_get(self,"@source"));
    >
    > I get this error:
    >
    > eventlog.c(554) : error C2102: '&' requires l-value
    > eventlog.c(554) : error C2198: 'rb_string_value_ptr' : too few actual
    > parameters


    I had the same experience. Unfortunately StringValue*() is not a
    direct replacement for STR2CSTR, as it takes the address of the
    parameter,

    #define StringValue(v) rb_string_value(&(v))
    #define StringValuePtr(v) rb_string_value_ptr(&(v))
    #define StringValueCStr(v) rb_string_value_cstr(&(v))

    My solution was

    VALUE tmp = rb_iv_get(self,"@source");
    lpSourceName = (LPCTSTR)StringValuePtr(tmp);





    __________________________________
    Do you Yahoo!?
    New and Improved Yahoo! Mail - Send 10MB messages!
    http://promotions.yahoo.com/new_mail
    Jeff Mitchell, Jul 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    442
  2. mark

    Curious string behavior

    mark, Jan 28, 2004, in forum: Python
    Replies:
    2
    Views:
    303
    OKB (not okblacke)
    Jan 28, 2004
  3. BartlebyScrivener

    curious paramstyle qmark behavior

    BartlebyScrivener, Oct 20, 2006, in forum: Python
    Replies:
    7
    Views:
    353
    Jon Clements
    Oct 21, 2006
  4. Jim B. Wilson

    The curious behavior of integer objects

    Jim B. Wilson, Jan 15, 2007, in forum: Python
    Replies:
    15
    Views:
    394
    Carl Banks
    Jan 16, 2007
  5. Berger, Daniel

    Question on StringValuePtr, rb_str_dup

    Berger, Daniel, Sep 13, 2005, in forum: Ruby
    Replies:
    1
    Views:
    108
Loading...

Share This Page