Solved

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

Posted on 2000-04-01
4
524 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
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 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…

929 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

14 Experts available now in Live!

Get 1:1 Help Now