Solved

File Access Violations

Posted on 2001-07-05
2
161 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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