473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I tell (from C# code) if a .DLL is native or a .NET assemb

Hi,

How can I tell (from C# code) whether a .DLL contains native code or is
infact a .NET assembly?

I know that I could use Assembly.LoadFile() and see if it throws a
BadImageFormatException but I really don't want any exceptions in my normal
program flow...

sincerely,
martin
May 19 '06 #1
3 2590
Hello, martin!

m> How can I tell (from C# code) whether a .DLL contains native code or is
m> infact a .NET assembly?

m> I know that I could use Assembly.LoadFile() and see if it throws a
m> BadImageFormatException but I really don't want any exceptions in my
m> normal program flow...

You will have to analyze file PE format
( http://www.samspublishing.com/articl...p?p=25350&rl=1 )
links in the article are broken, here valid ones
( http://msdn.microsoft.com/msdnmag/issues/02/02/PE/ )

Here is the sample how to do this
( http://geekswithblogs.net/rupreet/ar.../02/58873.aspx )
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 19 '06 #2
One more way to check PE for managed code is "COM Descriptor Directory"
section. If it contains non zero value - file contains managed code

"Vadym Stetsyak" wrote:
Hello, martin!

m> How can I tell (from C# code) whether a .DLL contains native code or is
m> infact a .NET assembly?

m> I know that I could use Assembly.LoadFile() and see if it throws a
m> BadImageFormatException but I really don't want any exceptions in my
m> normal program flow...

You will have to analyze file PE format
( http://www.samspublishing.com/articl...p?p=25350&rl=1 )
links in the article are broken, here valid ones
( http://msdn.microsoft.com/msdnmag/issues/02/02/PE/ )

Here is the sample how to do this
( http://geekswithblogs.net/rupreet/ar.../02/58873.aspx )
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

May 19 '06 #3
> I know that I could use Assembly.LoadFile() and see if it throws a
BadImageFormatException but I really don't want any exceptions in my normal
program flow...


That's why you catch it.

And yet that's the only way to be sure. You can reinvent the wheel, but it
wouldn't be as good/accurate/fast as Microsoft's, and it may need to be
updated in the (unlikely?) event that new DLL formats are created.

Microsoft gave you a tool, use it.

May 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan | last post by:
Hi Gurus I got a very basic question to ask: When a .NET exe (MSIL) is first run, the JIT-compiler will converts the IL into native codes so that it can executes on the current machine. my...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
2
by: Bit byte | last post by:
I have some IP (intellectual property) concerns regarding IL code. 1). If I compile a native (i.e. 'unmanaged') C++ project (i.e. application or library) using C++ and the VC7.1 compiler tools,...
1
by: Scott McFadden | last post by:
What is the proper way to pass pointers by reference from managed c++ calls to native c++ calls? In managed C++, I have a pointer to an array of structures, that I pass to a native c++ method by...
14
by: John | last post by:
My friend told me that his company will migrate the VC++ win32 applications to C++ .NET windows applications. I don't understand why since currently Microsoft only supports .NET on windows...
2
by: ramaswamynanda | last post by:
Hello All, I have an application using ASP.NET. The database is SQLServer Express 2005. There is a table called ApartmentInfo in the database. All i am trying to do, is to "select * from...
0
by: eitanyan | last post by:
I am trying to create a Java to .Net interop and the way I am doing it is by creating a C# com object and a native unmanaged c++ dll that uses JNIEnv of java. the java is loading the native c++ dll...
12
by: Jorge | last post by:
<html><head></head><body><script> (function () { var watch = "Hola !"; (function f () { alert(watch) })(); alert(typeof f); })(); </script></body></html>
16
by: Wayne | last post by:
I've read that one method of repairing a misbehaving database is to save all database objects as text and then rebuild them from the text files. I've used the following code posted by Lyle...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.