Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Opening File

Posted on 2002-03-18
4
Medium Priority
?
246 Views
Last Modified: 2010-04-02
hi
i m opening a file from a CFileDialog


char * ch1 = dlgOpen.GetFileName().LockBuffer();
dlgOpen.GetFileName().ReleaseBuffer();
char * ch2 = dlgOpen.GetFolderPath().LockBuffer();
dlgOpen.GetFolderPath().ReleaseBuffer();

and trying to get the full path and file name of the file as one ..but the code above keeps giving me error when i run the program..compiles..anyone tell me whats wrong ? or have a better way of doing what i want to do ?
thanks
0
Comment
Question by:prinx
[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
4 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 200 total points
ID: 6877066
Call CDialog::GetPathName():

CFileDialog dlg;

...

if (dlg.DoModal() == IDOK)
  {
  CString str = dlg.GetPathName();

  // str has your full path, ex: c:\temp\temp.dat
  }

Good Luck,
Steve
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 6877067
That should be CFileDialog::GetPathName() :)
0
 
LVL 5

Expert Comment

by:ekc
ID: 6877069
> char * ch1 = dlgOpen.GetFileName().LockBuffer();

I think the error is caused by the assigning a string to char * var that doesn't hold any allocated memory.
Try to allocate some memory to this var before calling this function...
0
 

Author Comment

by:prinx
ID: 6878812
i found out the prob is caused by
dlgOpen.GetFolderPath().LockBuffer();

y is this so ? thanks. i've tried alocated mem and its the same
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

604 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