Opening File

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

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

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 ?
Question by:prinx
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
LVL 30

Accepted Solution

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,
LVL 30

Expert Comment

ID: 6877067
That should be CFileDialog::GetPathName() :)

Expert Comment

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

Author Comment

ID: 6878812
i found out the prob is caused by

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

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