The DLLImport Command
If you would like to import a Dynamically Linked Library into your project you will first need to include a reference to the System Runtume Interop Services. To do this, simply place the following code above your namespaces declaraction:
using System.Runtime.InteropServices;
Now that you have referenced the proper runtime services you can import your Library. To get an idea on how to use the DLLImport function for importing DLLs review this example source code:
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
The above code imports the MessageBox function from the user32.dll system file, allowing you to show a simple message box. To execute the newly imported code all you have to do address the function like so:
MessageBox(new IntPtr(0), "This Message was imported from the user32.dll Library", "A Message Box", 0);
This code will show a message box displaying the text, "This Message was imported from the user32.dll Library". This is just an example of one of the API functions included in your operating system. There are literally hundreds more that you might find useful for use in your application. All of them are made available by the simple DLLImport function.
Conclusion
You can import any third party CSharp library into your project using the DLLImport method, allowing you to execute any of it's functions that wish to use. You can even use some of the older API functions that are commonly used in Visual Basic 6, but are missing the newer .Net frameworks.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
Photoshop Tutorial: Color Correcting and Tone Enhancing PhotographsIn this easy step-by-step Photoshop tutorial you will learn how to enhance the tons and correct the colors of your photos to create a masterpiece.- How Do I Plan to Import, So I Can Sell on EBayOften as one searches the vast expanse of the internet, looking for tips or secrets on how to import from countries like China, India, etc. one finds a lot of experts. But if you use their method at a certain price, ...
- New Study Shows Age Plays Role in Preference for Domestic or Import CarsA recent study shows that the decision between purchasing a domestic or import vehicle might be likely to be determined by the age of the buyer. It was revealed that younger buyers tend to purchase more imports, and o...
Paula Poundstone Helping Nation's LibrariesYou may not know this about comedian Paula Poundstone, but she is raising money and awareness for libraries throughout the United States.- Public and School Libraries Are Adding Coffee Shops and CafesThe latest trend across the country is for libraries to add more features like cafes and coffee shops so they can compete with with other sources. This has resulted in a reduction in the number of books and periodical...
- Photoshop Tutorial: How to Digitally Create Beautiful White Teeth
- Tutorial: How to Sabotage Yourself
- Photoshop Tutorial : How to Apply a Weather Effect to Your Text ?
- Photoshop Tutorial: Changing the Color Tone of Your Photos
- Photoshop Tutorial: Learning How to Use and Load Brushes in Photoshop
- Photoshop Tutorial: Adding Digital Rain to Your Images
- Photoshop Tutorial: How to Change Hair Color in a Photo



