Select multiple files error.

I want to select multi files using CFileDialog:

	CFileDialog FileDlg (TRUE, NULL, NULL, OFN_ALLOWMULTISELECT );
	TCHAR strBuffer[4096];
	FileDlg.m_ofn.lpstrFile = strBuffer;
	FileDlg.m_ofn.nMaxFile =sizeof(strBuffer);

	if (FileDlg.DoModal()==IDOK)
	{
		CString csFname;
		CStringArray m_strArray;
		m_strArray.SetSize(0);
		POSITION pos = FileDlg.GetStartPosition();
		while (pos != NULL)
		{
			csFname = FileDlg.GetNextPathName(pos);
			TRACE("%s\n", csFname);
			m_strArray.Add(csFname);
			m_CListBox_ListBox.AddString(csFname.GetBuffer());
		}
	}

The error is that FileDlg.DoModal() give error :

"Unhandled exception at 0x00000000 in ReadFile.exe: 0xC0000005: Access
violation reading location 0x00000000."

What I am missing?
0
yqin_99 (193)
2/4/2008 9:34:25 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
1056 Views

Similar Articles

[PageSpeed] 53

>	TCHAR strBuffer[4096];

According to the documentation:

"When the user allocates their own buffer to accommodate
OFN_ALLOWMULTISELECT, the buffer cannot be larger than 2048 or else
everything gets corrupted (2048 is the maximum size).
"

>	FileDlg.m_ofn.nMaxFile =sizeof(strBuffer);

Ought to be:

	FileDlg.m_ofn.nMaxFile = _countof(strBuffer);

Dave
0
davidl7375 (2060)
2/4/2008 9:47:25 PM
Initialize the strBuffer by putting a 0 as the first character.

strBuffer[0] = 0;

what is going on is that the FileDialog thinks that you are supplying it an 
initial filename in the lpstrFile variable, and since its uninitialized, it 
is crashing.


AliR.


"kathy" <yqin_99@yahoo.com> wrote in message 
news:474fb909-4e28-4cf1-87e7-94a8b1d9fdd8@k2g2000hse.googlegroups.com...
>I want to select multi files using CFileDialog:
>
> CFileDialog FileDlg (TRUE, NULL, NULL, OFN_ALLOWMULTISELECT );
> TCHAR strBuffer[4096];
> FileDlg.m_ofn.lpstrFile = strBuffer;
> FileDlg.m_ofn.nMaxFile =sizeof(strBuffer);
>
> if (FileDlg.DoModal()==IDOK)
> {
> CString csFname;
> CStringArray m_strArray;
> m_strArray.SetSize(0);
> POSITION pos = FileDlg.GetStartPosition();
> while (pos != NULL)
> {
> csFname = FileDlg.GetNextPathName(pos);
> TRACE("%s\n", csFname);
> m_strArray.Add(csFname);
> m_CListBox_ListBox.AddString(csFname.GetBuffer());
> }
> }
>
> The error is that FileDlg.DoModal() give error :
>
> "Unhandled exception at 0x00000000 in ReadFile.exe: 0xC0000005: Access
> violation reading location 0x00000000."
>
> What I am missing? 


0
AliR3470 (3235)
2/4/2008 9:53:25 PM
You may find this post I recently wrote on MSDN Visual C++ forum to be 
useful:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2790018&SiteID=1

Giovanni


"kathy" <yqin_99@yahoo.com> ha scritto nel messaggio 
news:474fb909-4e28-4cf1-87e7-94a8b1d9fdd8@k2g2000hse.googlegroups.com...
>I want to select multi files using CFileDialog:
>
> CFileDialog FileDlg (TRUE, NULL, NULL, OFN_ALLOWMULTISELECT );
> TCHAR strBuffer[4096];
> FileDlg.m_ofn.lpstrFile = strBuffer;
> FileDlg.m_ofn.nMaxFile =sizeof(strBuffer);
>
> if (FileDlg.DoModal()==IDOK)
> {
> CString csFname;
> CStringArray m_strArray;
> m_strArray.SetSize(0);
> POSITION pos = FileDlg.GetStartPosition();
> while (pos != NULL)
> {
> csFname = FileDlg.GetNextPathName(pos);
> TRACE("%s\n", csFname);
> m_strArray.Add(csFname);
> m_CListBox_ListBox.AddString(csFname.GetBuffer());
> }
> }
>
> The error is that FileDlg.DoModal() give error :
>
> "Unhandled exception at 0x00000000 in ReadFile.exe: 0xC0000005: Access
> violation reading location 0x00000000."
>
> What I am missing? 


0
2/4/2008 10:20:09 PM
"kathy" <yqin_99@yahoo.com> ha scritto nel messaggio 
news:474fb909-4e28-4cf1-87e7-94a8b1d9fdd8@k2g2000hse.googlegroups.com...

Moreover, to add to what others wrote:

> TRACE("%s\n", csFname);

better a:

 TRACE( "%s\n", (LPCTSTR)csFname );

> m_CListBox_ListBox.AddString(csFname.GetBuffer());

 m_CListBox_ListBox.AddString(csFname);

is fine, no need for GetBuffer() - which I think also requires a 
ReleaseBuffer.

Giovanni


0
2/4/2008 10:25:30 PM
"David Lowndes" <DavidL@example.invalid> ha scritto nel messaggio 
news:uf1fq3h93am5pa9u0k3cbruhhglqi4o6jt@4ax.com...

> According to the documentation:
>
> "When the user allocates their own buffer to accommodate
> OFN_ALLOWMULTISELECT, the buffer cannot be larger than 2048 or else
> everything gets corrupted (2048 is the maximum size).

David: where is that from?

I've not read that here:

"OPENFILENAME Structure"
http://msdn2.microsoft.com/en-us/library/ms646839.aspx

I tried a piece of code with a buffer allocated using more than 2048 TCHARs, 
and I saw no corruption.

However, if the official documentation states that, I agree that we must 
obey official docs.

Could you please post a link?

Thanks,
Giovanni


0
2/4/2008 10:32:09 PM
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message 
news:O#hSu33ZIHA.5088@TK2MSFTNGP06.phx.gbl...
>
> "David Lowndes" <DavidL@example.invalid> ha scritto nel messaggio 
> news:uf1fq3h93am5pa9u0k3cbruhhglqi4o6jt@4ax.com...
>
>> According to the documentation:
>>
>> "When the user allocates their own buffer to accommodate
>> OFN_ALLOWMULTISELECT, the buffer cannot be larger than 2048 or else
>> everything gets corrupted (2048 is the maximum size).
>
> David: where is that from?


Hi Giovanni.

I tracked that down in the docs for the MFC CFileDialog Class 
(http://msdn2.microsoft.com/en-us/library/dk77e5e7(VS.80).aspx).

I was interested too, as I've never heard that :-D

Mark

-- 
Mark Salsbery
Microsoft MVP - Visual C++




>
> I've not read that here:
>
> "OPENFILENAME Structure"
> http://msdn2.microsoft.com/en-us/library/ms646839.aspx
>
> I tried a piece of code with a buffer allocated using more than 2048 
> TCHARs, and I saw no corruption.
>
> However, if the official documentation states that, I agree that we must 
> obey official docs.
>
> Could you please post a link?
>
> Thanks,
> Giovanni
>
> 
0
Mark
2/4/2008 11:33:05 PM
>I was interested too, as I've never heard that :-D

I'm sure that I've also used much bigger buffers (in trial examples -
never needed it in real-life), so I wonder if that documentation is a
hangover from Win16?

Dave
0
davidl7375 (2060)
2/5/2008 12:14:41 AM
I have an application with a 16K buffer that works fine with multiple files. 
I often select over a hundred files.  For example, this works OK:

 // Change the title to something more appropriate than "Save As"
 CString cs = _T("My Title");
 CString FileBuffer;
 dlg.m_ofn.lpstrTitle = cs;
 dlg.m_ofn.lpstrFile = FileBuffer.GetBuffer(16384);
 dlg.m_ofn.nMaxFile = 16384;

 if (dlg.DoModal() == IDOK) {
  CWaitCursor wait;
  POSITION Pos = dlg.GetStartPosition();
  while(Pos != NULL) {
    CString csFile = dlg.GetNextPathName(Pos);
    // Do something
    CString csFileOnly = GetFileOnly(csFile);
    CString csFolderOnly = GetFolderOnly(csFile);
   }
 }

Plus, why would it say <Very large number> in the parameter example.  I 
don't know anyone who thinks 2048 is a very large number unless they are 
talking about age :o)

Tom

"David Lowndes" <DavidL@example.invalid> wrote in message 
news:ngafq35bs8uqp3h9envla7ulrbsmd3ungs@4ax.com...
> >I was interested too, as I've never heard that :-D
>
> I'm sure that I've also used much bigger buffers (in trial examples -
> never needed it in real-life), so I wonder if that documentation is a
> hangover from Win16?
>
> Dave 

0
tom.nospam (3240)
2/5/2008 4:21:31 AM
"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospam> ha scritto nel 
messaggio news:A3645B9D-574B-4DCC-B572-9FD29EE8E8F3@microsoft.com...

Hi Mark,

> I tracked that down in the docs for the MFC CFileDialog Class 
> (http://msdn2.microsoft.com/en-us/library/dk77e5e7(VS.80).aspx).
>
> I was interested too, as I've never heard that :-D

Yes!

Very strange :)

Giovanni


0
2/5/2008 8:50:37 AM
"Tom Serface" <tom.nospam@camaswood.com> ha scritto nel messaggio 
news:D1C347B8-9307-4E4D-A9FC-76ECEC5DFF4E@microsoft.com...

> Plus, why would it say <Very large number> in the parameter example.  I 
> don't know anyone who thinks 2048 is a very large number unless they are 
> talking about age :o)

:)

....But maybe in Win16 time it was a very large buffer!

I think that David's hypothesis (hangover from Win16) is correct.

G


0
2/5/2008 8:53:13 AM
Yeah, I often find the MSDN system incredibly difficult to use because there 
are so many versions of the same thing.  Most of the time I get a redirect 
message and lots of times when I click on a link I get a "We can't display 
that" kind of message.  It is frustrating.  Plus, it takes so darn long to 
display anything because they have the huge frame on the left with the TOC 
and you can't even scroll until it decides you can and ... <slap> OK, I'll 
stop griping now.  It's just sad because first we lost the really cool local 
help (like it used to be) and now the online help is not so useful either. 
Also, I think Google moves MSDN down a few pages a lot of the time because 
of their political battle.

Tom

"Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message 
news:un1S6S9ZIHA.6140@TK2MSFTNGP02.phx.gbl...
>
> "Tom Serface" <tom.nospam@camaswood.com> ha scritto nel messaggio 
> news:D1C347B8-9307-4E4D-A9FC-76ECEC5DFF4E@microsoft.com...
>
>> Plus, why would it say <Very large number> in the parameter example.  I 
>> don't know anyone who thinks 2048 is a very large number unless they are 
>> talking about age :o)
>
> :)
>
> ...But maybe in Win16 time it was a very large buffer!
>
> I think that David's hypothesis (hangover from Win16) is correct.
>
> G
>
> 

0
tom.nospam (3240)
2/5/2008 3:57:22 PM
Reply:

Similar Artilces:

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

extern BYTE error when executing
// GAS.cpp : Defines the class behaviors for the application. #include "...h" // CGASApp .... // CGASApp construction CGASApp::CGASApp() {... } // The one and only CGASApp object CGASApp theApp; // CGASApp initialization extern BYTE dR0h[51],dR0l[51]; extern BYTE dR1h[51],dR1l[51]; extern BYTE dR2h[51],dR2l[51]; extern BYTE dHl[51][1000],dHh[51][1000]; extern BYTE dXl[51][1000],dXh[51][1000]; /////////GAS is a SDI application programe,and extern BYTE defined as above. // STATICFORM.cpp : implementation file #include "...h" // STATICFORM.dialog extern BYTE dR0l[51],dR...

Searaching for Contacts with multiple categories
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Using the search function, it seems I am not able to search for a contact that belongs to more than one category. It seems to only recognize the contacts primary category. Can this be true? <br> It makes searching for contacts by multiple characteristics (categories, used like keywords), not possible. Please tell me there is another way. To clarify, I am trying to find an item whose category is both A and B. I can of course search for A or B, even though they have other categories assigned to them ...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

WriteFile, insert data in the middle of the file.
Hello, What I want to do is to insert data (not overwrite existing data) in the middle of a big file. Does WriteFile( ) have this option? If there's no way to insert data in the middle, I guess I have to read out all the data from the insertion point, and append my new data, and write them back to the file? Isn't this too inefficient? Anybody knows how OS handles this kind of "insert in the middle" scenario? Thank you, I appreciate your opinion. wk Well you answered your own question. There is no way to write to the middle of the file without overwriting what's ...

Function to multiple ranges
Which function may be used with multiple ranges? Commonly used "lookups", "index" and "match" don't seem to work. Is there a trick in multiple ranges? Tomek Polak Some functions work, others don't. INDEX has a 4th argument that allows you to specify the area (which of the multiple ranges). The lookup and match functions require a single contiguous block of cells. On Wed, 29 Oct 2003 14:19:08 +0100, "Tomek" <tpolak@poczta.onet.pl> wrote: >Which function may be used with multiple ranges? > >Commonly used "lookups",...

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Outlook Error Message #6
Hi, Since I've installed Office 2003, I am experiencing error messages. I've uninstalled Office 2003 and re-installed and I am still getting the following error message. "Managed MAPI Service Catastrophic Failure", this error message which prevents me from opening and reading my email. Can anyone offer a resolution? Thanks, Jenae ...

Multiple Attributes
I have created a custom Entity - "Inventory" This has a relationship with Accounts which is used to show the location of a piece of hardware - a lookup field is used to choose an account. All good. However I'd also like to have a couple of other lookups for Supplier and Manufacturer. These are both stored in Accounts so they'd need to reference an entry in Accounts again. Is this possible? I know you cannot create multiple relationships between entities but can you create multiple attributes using the one relationship? Can anyone help with this - still got no further.....

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

NTFS file meta data
This is a multi-part message in MIME format. ------=_NextPart_000_008A_01CAFF1D.F88487D0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit How can I set the From, Subject, To properties of Outlook MSG files to display in a manner as EML files? I have folders of thousands of these files and would love to create a batch processors to do this. TIA Russ ------=_NextPart_000_008A_01CAFF1D.F88487D0 Content-Type: image/png; name="Capture.PNG" Content-Transfer-Encoding: base64 Conte...

"Disk is full" error when opening Excel 2000.
I am getting a "disk is full" error when opening MS Excel on my laptop (not connected to any servers/LAN). I am running Windows 2000 and my Excel version is 2000 as well. Additionally I can not open MS Word or Adobe Acrobat either as these applications are giving errors that it can not find the file. Have others experienced this and if so, do you know of a solution for fixing it? ...

MAPI Spooler error #2
hello: i am having a problem with sending e-mails with my outlook 2000. for some reason the outbox does not seem to send a few e-mails since yesterday. when i click on the selected e-mail it says "can't open this item. the mapi spooler has already begun transmitting this message" all my email settings and internet connection are fine. i also tried to repair the office using the installation cd, but the problem did not go away. the e-mails are being received by people, but the they still appear in my outbox as never being sent? it looks like the spooler grabed the...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

Installation error with SBS
We are installing CRM server 3.0 under SBS 2003. The setup terminates with the following "the Microsoft search service cannot be administered under the present account" changing the services logon account from the "local system' account to the administrators account made no difference. All replies are valued very much. thanks, MSSEARCH is a component of Microsoft SQL Server 2000. You must change the MSSEARCH and probably all other MSSQL service to run as "local System" and then change the CRM services to run as NetworkService. This can be done via: Start > R...

Add users to a Distribution Group using csv file
Is it possible? I have a list of approx 3200 users that I want to add to a common duistribution group w/o having to do it manually. At present I have a csv file with all the users that I want to be in the group. Is there a way to import them into the group using this file w/o recreating their accounts using csvde or ldife? TIA. Should be http://support.microsoft.com/?kbid=237677 http://www.computerperformance.co.uk/Logon/Logon_CSVDE_Bulk.htm Nue "kage13" <kage13@discussions.microsoft.com> wrote in message news:F8FB3846-DCDE-473F-9F1D-89E8CF0A66E3@microsoft.com... &...

Error: Object could not be found
Hey y'all. Using Outlook 2003 on XP Home with the MS Mail 'hack (http://www.outlook-tips.net/howto/msmail.htm) installed, and I' having a problem. When composing a message, all goes well until I click Send. It the pops up an error saying that "Operation could not be completed: Objec could not be found". Initially, the titlebar of the messagebox sai Microsoft Word 2003, so I assumed it was because of the editor, bu after changing the editor (to Outlook), the error persists, only wit the titlebar value being Microsoft Office Outlook 2003. Any idea how I can fix thi...

Data from multiple sheets and workbooks
Each week I receive a workbook from one of my customers. It contains mutliple sheets with salesnumbers from all the branch of my customer. Each sheet contains from 1 000 to 15 000 lines of salesdata. Every article sold gets one line in the sheets. Each workbook are named "weeknr.xls" and are stored in the same folder. Now my question/problem. I need to gather all sales info for one branch on one article from all the weeks. I know how to get the data from one workbook to another, but how do I get it to scan all the workbooks in the folder. Any ideas. Dim oFSO Sub LoopFolder...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

outlook files taken over by www.jraun search
Hi Anyone have this problem. My outlook personal files systems open to a search through www.jraun.com. I cannot seem to get rid of this problem is it a new trojan or something? "ncw" <anonymous@discussions.microsoft.com> wrote in message news:<03bc01c3c36b$fc7c2fe0$a501280a@phx.gbl>... > Hi > Anyone have this problem. My outlook personal files > systems open to a search through www.jraun.com. I cannot > seem to get rid of this problem is it a new trojan or > something? I've got it too. No luck in getting rid of it yet. ncw <anonymous@discus...

I need a templet or file for creating a personal checkbook.
I would like a templet or file that I can covert to Lotus 123 that will track my checks. There is a few templets out there but I can not convert them to Lotus? Any help would be appericated in advance. Mike ...

multiple V-lookup
I have a worksheet that has multiple rows that have the same name. For example. I have a worksheet that looks like this Name 401k FICA Julie 100 200 Patrick 200 400 Sam 50 100 Julie 100 200 Julie 100 200 Patrick 200 400 I am trying to figure out how I can have excel look at the worksheet and find all entries labed Patrick and return the columns already summed. Similar to a vlookup but able to know that if I want the 401k column it should return ...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Error during sending and no new messages, Outlook 97
I use a Internet E-mail with an adress with yahoo. When I try to send an email I have the next message : The TCP/IP connection was unexpectedly terminated by your mail server. If the problem persists, contact your LAN Administrator or Internet Provider. I don't what to do because right now I used without trouble Outlook Express, whithout such problem. Besides I can not receive any email. Thanks ...