Solved

File Access Violations

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
SUM 2 INTEGER ARRAYS INTO 1 10 111
DBGrid or StringGrid ? 6 119
Slow Restore if incremental backups using RDiff.exe 4 39
how can i delete one control based on its tagstring ? 6 34
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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