?
Solved

Need help initializing a variable of type LPWSTR?

Posted on 2001-06-15
3
Medium Priority
?
4,585 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

718 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