Solved

Need help initializing a variable of type LPWSTR?

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

615 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