Solved

GetFileOpenName/GetFileSaveName is causing other stuff to bomb

Posted on 2004-03-22
7
1,506 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

758 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

18 Experts available now in Live!

Get 1:1 Help Now