Solved

Need help initializing a variable of type LPWSTR?

Posted on 2001-06-15
3
4,143 Views
Last Modified: 2008-01-09
I am currently getting the following error when I try to initialize a member of the AT_INFO structure:

C:\rocklobsterj\Ptest1\Netschedule.cpp(25) : error C2440: '=' : cannot convert from 'char [42]' to 'unsigned short *'

The NetScheduleJobAdd() function takes three parameters, one of which uses an AT_INFO structure.  One of its members is of type LPWSTR.  


typedef struct _AT_INFO {
    DWORD   JobTime;
    DWORD   DaysOfMonth;
    UCHAR   DaysOfWeek;
    UCHAR   Flags;
    LPWSTR  Command;
} AT_INFO, *PAT_INFO, *LPAT_INFO;
 
Here's the way I'm attemting to initialize the 'Command' member:

AT_INFO myATINFO;
  myATINFO.JobTime = 36000000 ;
  myATINFO.DaysOfMonth = 0;
  myATINFO.DaysOfWeek = 1;        
  myATINFO.Flags = JOB_RUN_PERIODICALLY;
  myATINFO.Command = "c:\\rocklobsterj\\version1\\classes\\RLCITEST";  

0
Comment
Question by:qbawler311
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6195215
The problem is that 'Command' is a UNICODE string:

LPWSTR  Command;

In your case (if you're using a string LITERAL), changing the initialization will solve the problem:

myATINFO.Command = L"c:\\rocklobsterj\\version1\\classes\\RLCITEST"; // note the 'L' declaring a UNICODE literal!

0
 
LVL 86

Expert Comment

by:jkr
ID: 6195239
BTW, if you have to deal with non-constant strings, you'll have to supply a conversion:

char acCommand [ MAX_PATH] = "c:\\rocklobsterj\\version1\\classes\\RLCITEST";
wchar_t awcCommand;

wsprintfW ( awcCommand, "%S", acCommand);

myATINFO.Command = awcCommand;
0
 

Author Comment

by:qbawler311
ID: 6206150
Thanks jkr, sorry so late.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now