Solved

GetFileOpenName/GetFileSaveName is causing other stuff to bomb

Posted on 2004-03-22
7
1,525 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
[X]
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
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
Industry Leaders: 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!

 
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

Independent Software Vendors: 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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

734 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