Solved

File Access Violations

Posted on 2001-07-05
2
162 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
2 Comments
 
LVL 2

Accepted Solution

by:
bugroger earned 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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