Solved

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

Posted on 2000-04-01
4
527 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 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