Solved

Need help initializing a variable of type LPWSTR?

Posted on 2001-06-15
3
4,308 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

820 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