?
Solved

How to assign a path of a file to a const WCHAR  * or const FSSpec *?

Posted on 2000-04-01
4
Medium Priority
?
530 Views
Last Modified: 2012-06-21
I'm trying to assign the path of a file to either:

const WCHAR *ptr;
or
const FSSpec *optr;

(These are contained in a structure called FILEIN in the header file.)


This is my path I want one of these to point to:
c:\\myfile.txt"

Here is the method that I'm assigning the values in:

int WINAPI Openfile(const FILEIN *fin)


In this method how do I set either ptr or optr to point to the file path?

Thanks :)

0
Comment
Question by:nicolac
[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
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 2677010
It would be helpful if we knew what FILEIN was.  You say it is a structure, but we could really use its definition.  but the basic idea should be that you declare an instance of the structure and fill in its data members, in particular the path.  Then you pass a pointer to this structure instance.   For example, if the structure has a member called "path" that is a char * pointer to the file path, you would do

FILEIN FilDat;

FilDat.path = "C:\\MYFILE.DAT";

OpenFile(&FilDat);

Let me know if you have any questions.  (More info from you woudl help though...)
0
 

Author Comment

by:nicolac
ID: 2677483
Here is the structure FILEIN:

STRUCTUREBEGIN(FILEIN) /*File Input info*/
#if !defined(MAC)
      const WCHAR *ptr;      // full path of file to open
#else
      const FSSpec *optr;      // file to open
#endif
.....
STRUCTUREEND

In the method

int WINAPI Openfile(const FILEIN *fin)

I want to set the value of either
const WCHAR *ptr;
or
const FSSpec *optr;

Does this explain it better?

You said: For example, if the structure has a member called "path" that is a char * pointer to the file path...
This is it:  const WCHAR *ptr;

0
 
LVL 22

Expert Comment

by:nietod
ID: 2677528
Then you would do

FILEIN FilDat;

FilDat.ptr = "C:\\MYFILE.DAT";
OpenFile(&FilDat);

except the string in this case is a wide-character string, so you need to isnure you assigning the pointer to a wide character string. If you are using a string literal (like above) you do that by placing a "L" (long) before the string like

FilDat.ptr = L"C:\\MYFILE.DAT";

if you are initializing the pointer to point to a buffer that stores the string (rather than a strign literal), then you need to make sure the buffer is declared a storign wide characters.

Does that help?
0
 

Author Comment

by:nicolac
ID: 2677709
Great thats it, thanks :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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.
Suggested Courses

764 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