copying char to cepropval.val.lpwstr

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Scott Allen (scottelloco_at_yahoo.com)
Date: 11/08/04


Date: 8 Nov 2004 08:24:08 -0800

Hello,

I'm fairly new to PPC development and C++ development in general. I
have CEPROVAL structure and I'd like to copy a char value into the
CEPROVAL's val.lpwstr property. I have been using the A2W macro to
copy strings into the lpwstr property, but this dosen't seem to work
for chars (the compiler gives an error, see below.) I've tried casting
the char to an LPWSTR, but that gives me a runtime error when I try to
copy the value into lpwstr. I'm sure the problem is obvious to a more
experienced C++ programmer, but I haven't been able to find it.

I've modified my code a little for simplcity, but here is basically
what I'm trying to do:

tblProceduresHistory is the struct that contains my chars. I have
already populated this struct and just want to copy the values into a
CEPROPVAL.

struct tblProceduresHistory
{
        char InstitutionName[102];
        char Status;
};

CEPROPVAL Record[2];
tblProceduresHistory HistoryRecord;

memset(Record, 0, sizeof(Record));

...code to open database, etc...

Record[0].propid = MAKELONG(CEVT_LPWSTR, 0);
Record[0].val.lpwstr = A2W(HistoryRecord.InstitutionName); //***THIS
WORKS
Record[1].propid = MAKELONG(CEVT_LPWSTR, 1);
Record[1].val.lpwstr = A2W(HistoryRecord.Status); //***THIS
FAILS

This is the error I get from the compiler:
error C2664: 'strlen' : cannot convert parameter 1 from 'char' to
'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
error C2664: 'AfxA2WHelper' : cannot convert parameter 2 from 'char'
to 'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast

Thanks for any help and suggestions.
-Scott



Relevant Pages