Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File Access Violations

Posted on 2001-07-05
2
Medium Priority
?
167 Views
Last Modified: 2010-04-06
Hello.

I recently rewrote my MP3 player and although in the past I have never coded support for reading ID3 tags (I name my files in a fashion that I never really needed to) for some reason this time I did.  And I've run into a problem.

I run Win2k, and if I play the MP3 file and then try reading the tag I get errors.  This problem isnt present on Win9x systems of course because they have much more lax file sharing restrictions.

So anyway, Im wondering if there is any way to read the tag after the MP3 has already started playing.  I was told there are ways to make Win2k less anal about file sharing but that would mean users would also have to make the change.  If it helps any, I am using a TFileStream and the fmOpenRead access mode.  Originally I was using AssignFile/Reset/CloseFile and tried the TFileStream hoping to have more luck but of course I didnt...

Thanks.
0
Comment
Question by:MannSoft
[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
2 Comments
 
LVL 2

Accepted Solution

by:
bugroger earned 200 total points
ID: 6257504
Hi,

Look at these functions:

 - CreateFile
 - SetFilePointer
 - ReadFile / ReadFileEx
 - CloseHandle


Here is an example how your function look like:

Function GetMP3Tag(Mp3FilePath : string) : string;
Var
 Mp3File    : THandle;
 TagBuffer  : array[0..999] of char;
 BytesRead  : Dword;

Begin
 MP3File := createFile( PChar(Mp3File),
                        GENERIC_READ,
                        FILE_SHARE_READ,
                        NIL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        0);

 IF MP3File = INVALID_HANDLE_VALUE then
 Begin
  CloseHandle(Mp3File);
  ShowMessage('ERROR');
 End else
 Begin
  SetFilePointer(Mp3File, "TagOffset", NIL, FILE_BEGIN);
  ReadFile(Mp3File, TagBuffer[0], "BytesToRead", BytesRead, NIL);
  CloseHandle(Mp3File);
 End;
End;

GL
 Bug
0
 
LVL 6

Author Comment

by:MannSoft
ID: 6257872
I always do this...I ask a question and think "oh I should have tried this" and 10 minutes later I have the answer myself.  Using "fmOpenRead or fmShareDenyNone" as the file mode in the TFileScream.Create procedure did the trick.

But since you gave an answer already which may come in handy if I need to read a file using only the WinAPI in the future, I'll accept it.

Thanks

(PS: If you feel like answering another question, I could really use the method for getting the caption of the window which currently has focus (the topmost window I guess it would be).  I think I'll search through the help files for awhile longer before officially asking it for points just in case I find that one too :-) )
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

715 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