is a file an executable ? 
Author Message
 is a file an executable ?

I have an application doing some directory browsing and trying to get info
for files.
it use LoadLibrary first ...
it could happened a file is not an executable (like LoadLibrary("inf.txt")),
and LoadLibrary display an annoyous warning panel.
is there a way to check first that the file is a library or not ?


Tue, 18 Oct 2005 22:53:14 GMT  
 is a file an executable ?

Quote:
> I have an application doing some directory browsing and trying to get info
> for files.
> it use LoadLibrary first ...
> it could happened a file is not an executable (like

LoadLibrary("inf.txt")),

Quote:
> and LoadLibrary display an annoyous warning panel.
> is there a way to check first that the file is a library or not ?

Try something like this which I haven't compiled:

UINT uOldErrMode;

uOldErrMode = SetErrorMode(
                         SEM_FAILCRITICALERRORS |
                            SEM_NOGPFAULTERRORBOX  |
                              SEM_NOOPENFILEERRORBOX);

// Load your library here

SetErrorMode(uOldErrMode);

Regards,
Will



Tue, 18 Oct 2005 23:12:28 GMT  
 is a file an executable ?

Quote:
> I have an application doing some directory browsing and trying to get info
> for files.
> it use LoadLibrary first ...
> it could happened a file is not an executable (like LoadLibrary("inf.txt")),
> and LoadLibrary display an annoyous warning panel.
> is there a way to check first that the file is a library or not ?

You can get a reasonable degree of certainty by reading in the first two bytes
of the file and comparing them to "MZ", which is what all dos and windows
executables (including dlls and drivers) start with.  You might get a few
false positives, but I doubt it...most binary file types have a unique header
that doesn't start with "MZ", and although an arbitrary text file might start
with MZ, it's not a very common way to start a document...For extra certainty
(if you only care about windows apps), you can parse the DOS header to get the
PE header and check that it is valid ("PE(nul)(nul)")

You can also make reasonable assumptions based on the file extension...

Ken



Tue, 18 Oct 2005 23:16:07 GMT  
 is a file an executable ?
Have you tried calling GetBinaryType?
- Keith MacDonald


Quote:
> I have an application doing some directory browsing and trying to get info
> for files.
> it use LoadLibrary first ...
> it could happened a file is not an executable (like

LoadLibrary("inf.txt")),
Quote:
> and LoadLibrary display an annoyous warning panel.
> is there a way to check first that the file is a library or not ?



Wed, 19 Oct 2005 22:43:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Request on how to get source file from executable file

2. I am new to programming and am lost

3. Running the executable file off the network drive

4. Wrapping a readme file and executable program

5. Can a program change its executable file ?

6. Run other executable files from C# program and wait for it returns

7. where is the executable file from libf2c?

8. Executable Code in Header Files (!?)

9. Executable Files

10. Need HELP with a creating a self-extracting executable file

11. Executable File Format

12. putting executable code into an external file

 

 
Powered by phpBB® Forum Software