Solved

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

Posted on 2000-04-01
4
521 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great thats it, thanks :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

7 Experts available now in Live!

Get 1:1 Help Now