Solved

Opening File

Posted on 2002-03-18
4
208 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
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 50 total points
Comment Utility
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
Comment Utility
That should be CFileDialog::GetPathName() :)
0
 
LVL 5

Expert Comment

by:ekc
Comment Utility
> 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 clear a vector as well as how to detect empty vectors in C++.

728 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

14 Experts available now in Live!

Get 1:1 Help Now