Solved

GetFileOpenName/GetFileSaveName is causing other stuff to bomb

Posted on 2004-03-22
7
1,519 Views
Last Modified: 2013-12-26
I need to use either the GetFileOpenName or GetFileSaveName to allow the user to browse to a specific file that they want to link to document.  (If there are any other ways to opening a windows file browser, please let me know.)  Anyway, it works fine, but after I browse and find the file, it causes other unrelated things to bomb.  For instance, the application is no longer able to retrieve data from my profile (.INI file)...and then icons in the treeview start disappearing.  It's almost like the GetFileOpenName/GetFileSaveName functions affected the memory or something...like the memory needs to be freed or something.  But I can't find anywhere that tells me I need to do that...

Does anyone have any insight to shed on this issue?  Thanks!
0
Comment
Question by:aznevon
7 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 10654118
Presuming this is PowerBuilder, you may get better results posting in the PowerBuilder area:
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/
0
 
LVL 23

Expert Comment

by:chensu
ID: 10654452
Have you specified the OFN_NOCHANGEDIR flag?
0
 
LVL 5

Accepted Solution

by:
berXpert earned 125 total points
ID: 10658334
Hi,

GetFileOpenName & GetFileSaveName actually change your working path, your icons need to be on that path to show in your application, so when you change your path they disappear.

To solve this you can include your icons and bmp's in your Resource file (.PBR file) so when you build your EXE you allways have them in memory.

BerX
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 10658711
Hi,

Here's the code that I used n One of my Apps for making sure my app picks up the ini form the correct path:

External functions:
Function ulong GetModuleFileName (ulong hinstModule, ref string lpszPath, ulong cchPath ) Library "KERNEL32.DLL" Alias for "GetModuleFileNameA"
Function ulong GetCurrentDirectory (ulong nBufferLength, ref string lpBuffer) Library "KERNEL32.DLL" Alias for "GetCurrentDirectoryA"

//If running from PB (development mode), Then INI file is in current dir,
//else it is in the same dir as the app exe.
if Handle(GetApplication()) <=0 then
      ls_modulepath = space(128)
      GetCurrentDirectory(128,ls_modulepath)
else
      ls_ModulePath = space(128)
      GetModuleFileName(Handle(loccount),ls_ModulePath ,128)
      ll_lastPos = lnv_string.of_lastpos(ls_ModulePath, "\")
      ls_modulepath = Left(ls_ModulePath, ll_lastPos -1)
end if

ls_IniPath = ls_modulepath +"\UtilDBquery.ini"

Other Options may be setting the path of the ini as an environemtn variable.

For Bitmaps, BerX's solution is prefrable.. another option may be to Overide the functions GetFileOpenName and GetFileSaveName, to chenge the current dir back to what was earlier:

Function boolean SetCurrentDirectory (ref string lpPathName) Library "KERNEL32.DLL" Alias for "SetCurrentDirectoryA"

function f_GetFileOpenName :

ls_CurrentDir = space(128)
GetCurrentDirectory(128,ls_CurrentDir)
GetFileOpenName (.......)
SetCurrentDirectory(ls_CurrentDir)

Regards,
Vikas D

0
 

Author Comment

by:aznevon
ID: 10658767
I knew what I had to do after reading berXpert's solution...I did the following:

ls_exe_dir = GetCurrentDirectory ()
GetFileSaveName("Browse to Document", ls_filepath, ls_filename, "", "All Files (*.*),*.*", ls_filedefault)
ChangeDirectory (ls_exe_dir)

And it works fine...

Thanks...
0
 
LVL 23

Expert Comment

by:chensu
ID: 10659808
You don't have to call GetCurrentDirectory() and ChangeDirectory(). As I said above, the OFN_NOCHANGEDIR flag does that for you automatically.
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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

809 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