Click here to Skip to main content
15,892,298 members
Articles / Desktop Programming / Win32

ADSdotNET: A DLL for Using Alternate Data Streams from .NET Languages

Rate me:
Please Sign up or sign in to vote.
4.14/5 (5 votes)
24 Apr 2011CPOL4 min read 40.4K   984   16  
With this class, you can use ADS with C#, VB.NET, and other .NET languages without P/Invoke
// ADSdotNET.h

#pragma once

using namespace System;

namespace AdsDotNet 
{
	public ref class AdsHandler
	{
	private:
		//members:
		String ^filename;
		ref class AdsStore
		{
		private:
			System::Collections::Generic::Dictionary<String^, IntPtr> ^name_handle_dict;
			System::Collections::Generic::Dictionary<String^, System::IO::FileStream ^> ^name_filestream_dict;

		public:
			AdsStore()
			{
				name_handle_dict = gcnew System::Collections::Generic::Dictionary<String^, IntPtr>();
				name_filestream_dict = gcnew System::Collections::Generic::Dictionary<String^, System::IO::FileStream ^>();
			}

			void Add(String ^name, IntPtr handle, System::IO::FileStream ^filestream)
			{
				name_handle_dict->Add(name, handle);
				name_filestream_dict->Add(name, filestream);
			}

			void Remove(String ^name)
			{
				name_handle_dict->Remove(name);
				name_filestream_dict->Remove(name);
			}

			IntPtr GetHandle(String ^name)
			{
				return name_handle_dict[name];
			}

			System::IO::FileStream ^GetFilestream(String ^name)
			{
				return name_filestream_dict[name];
			}

			bool IsAdsInStore(String ^name)
			{
				return name_handle_dict->ContainsKey(name);
			}
		};

		AdsStore ^ads_store;

		// private methods:
		wchar_t *ConvertManagedStringToCharPointer(String ^managed_string);
		System::IO::FileStream ^CreateAdsFileStream(HANDLE file_handle);
		DWORD CloseFileHandle(HANDLE file_handle);
		void ThrowAppropriateCreateFileException(DWORD errorcode);

	public:
		//ctor:
		AdsHandler(String ^filename);

		// public methods:
		void AddAds(String ^adsname);
		void DeleteAds(String ^adsname);
		bool AdsExists(String ^adsname);
		void CloseAds(String ^adsname);
		bool IsAdsOpen(String ^adsname);
		System::Collections::Generic::List<System::String^> ^GetAdsList();
		System::IO::FileStream ^OpenAds(String ^adsname);
		System::IO::FileStream ^OpenAds(String ^adsname, bool readonly);
		System::String ^GetCompleteFilename(String ^adsname);
	};

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions