curious behavior with StringValuePtr()

D

Daniel Berger

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
 
J

Jeff Mitchell

--- Daniel Berger said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top