473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

GetOpenFileName() crashes program

48
Hi,

I was wondering if anyone encountered the following error with GetOpenFileName().


The open dialog opens, and I hover my mouse over a file. The dialog shows the detailed info of the file like normal. I open my file and everything works as normal. I open the open dialog again. If I hover over any file again, the whole program is closed in a way that does not send any WM_CLOSE messages and not even windows shows up that there was an error.


A weird thing also is that this error only happends on 50% of the computer's i've tried with my program.

Maybe a work around that might work, is if there was a way of turning off the hovering detail display of files.

Ideas, thoughts?

Expand|Select|Wrap|Line Numbers
  1. void FileOpen(HWND hwnd)
  2. {
  3.  
  4.     OPENFILENAME ofn;
  5.     char* szFileName=new char[100];
  6.  
  7.     ZeroMemory(&ofn, sizeof(ofn));
  8.     szFileName[0] = 0;
  9.  
  10.     ofn.lStructSize = sizeof(ofn);
  11.     ofn.hwndOwner = 0;
  12.     ofn.lpstrFilter = "DCP Files (*.dcp)\0*.dcp\0All Files (*.*)\0*.*\0\0";
  13.     ofn.lpstrFile = szFileName;
  14.     ofn.nMaxFile = MAX_PATH;
  15.     ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  16.     ofn.lpstrDefExt = "dcp";
  17.  
  18.     bool worked=GetOpenFileName(&ofn);
  19.  
  20.     if(worked)
  21.         FileOpen2(hwnd, szFileName);
  22. }
  23.  
hwnd is the handle to the parent window.
Jul 30 '07 #1
2 4582
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1.     char* szFileName=new char[100];
  2.  
  3.     ofn.lpstrFile = szFileName;
  4.     ofn.nMaxFile = MAX_PATH;
  5.  
You have created a buffer for szFileName that is 100 bytes long, however you tell GetOpenFileName that it is MAX_PATH bytes long, on my implementation MAX_PATH is 260 so you are telling GetOpenFileName that szFileName is a buffer that is 160 bytes longer than it actually is.

Either use MAX_PATH where you allocate szFileName or pass the actual size of buffer pointed to by szFileName to GetOpenFileName.

It is always a mistake to information a called function that a buffer is longer than it really is.
Jul 30 '07 #2
qhimq
48
yeah i agree that is a mistake, however its not causing my program to completely close without an error message.
Jul 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: greeningster | last post by:
I have written an application in Visual C++ for a customer but it seems to crash randomly. Could anyone give me any help on how I could track this down ? Also, there appears there might be...
0
by: SS | last post by:
I tried a sample code provided in Microsoft .NET on how to make a call to Win32 GetOpenFileName. It crashed if I call the function, select a file and close the dialog and repeat the process several...
9
by: hhh12347 | last post by:
FolderBrowserDialog crashes on my Windows 2000 computer. Here is a C# test program: using System; using System.Windows.Forms; public class TestForm : Form { FolderBrowserDialog...
14
by: Rajko | last post by:
GetOpenFileName with flag OFN_ALLOWMULTISELECT will create error message if number of characters exceeds 29700 characters. I does not matter if you alocated enough space. It will use only first...
1
by: mnlarsen | last post by:
How do I set the default location to "My Computer" when using the GetOpenFileName call? I have tried the following but CSIDL_DRIVES doesn't appear to work. Any ideas? WCHAR szFile =...
5
by: Benoit Martin | last post by:
Hello, I am not expecting to get THE fix for my problem but I need help to get started in the right direction In one of my classes, I instantiate an object inherited from the...
41
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as...
0
SammyB
by: SammyB | last post by:
I am trying to get back to the way Office 97 allowed multiselect in GetOpenFileName: the order you selected was the order returned. This means that I must keep my own list of files which changes...
1
by: ssndk123 | last post by:
Hi, Using the UserPort program that changes permissions in XP so that I am able to write directly to the parallel port using assembler.. I'm trying to send out square wave pulses for x number...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.