Opening File

Posted on 2002-03-18
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 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error C2678: binary '!=': no operator found... 4 65
c++, dynamic object by json 1 60
I could not set window to top 4 44
keep track of class structure 1 20
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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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…
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.

733 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