Getting an array of bytes out of Windows::Storage::Streams::IBuffer

You can use IBufferByteAccess, through exotic COM casts: byte* GetPointerToPixelData(IBuffer^ buffer) { // Cast to Object^, then to its underlying IInspectable interface. Object^ obj = buffer; ComPtr<IInspectable> insp(reinterpret_cast<IInspectable*>(obj)); // Query the IBufferByteAccess interface. ComPtr<IBufferByteAccess> bufferByteAccess; ThrowIfFailed(insp.As(&bufferByteAccess)); // Retrieve the buffer data. byte* pixels = nullptr; ThrowIfFailed(bufferByteAccess->Buffer(&pixels)); return pixels; } Code sample copied from http://cm-bloggers.blogspot.fi/2012/09/accessing-image-pixel-data-in-ccx.html

How write a file using StreamWriter in Windows 8?

Instead of StreamWriter you would use something like this: StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync(); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0)) { using (DataWriter dataWriter = new DataWriter(outputStream)) { //TODO: Replace “Bytes” with the type you want to write. dataWriter.WriteBytes(bytes); await dataWriter.StoreAsync(); dataWriter.DetachStream(); } await outputStream.FlushAsync(); … Read more

“Could not load file or assembly System.Drawing or one of its dependencies” error on .Net 2.0, VS2010 and Windows 8

This is a bug. I have seen it too. It happens because your .resx file is pointing to 4.0.0.0 version of System.Drawing where one does not exist. To overcome this problem i usually edit the .resx in notepad to change 4.0.0.0 to 2.0.0.0. The bug is introduced by following the exact steps that you have … Read more

HttpClient Request like browser

Here you go – note you have to decompress the gzip encoded-result you get back as per mleroy: private static readonly HttpClient _HttpClient = new HttpClient(); private static async Task<string> GetResponse(string url) { using (var request = new HttpRequestMessage(HttpMethod.Get, new Uri(url))) { request.Headers.TryAddWithoutValidation(“Accept”, “text/html,application/xhtml+xml,application/xml”); request.Headers.TryAddWithoutValidation(“Accept-Encoding”, “gzip, deflate”); request.Headers.TryAddWithoutValidation(“User-Agent”, “Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 … Read more

Is the List.ForEach() method gone?

It’s indeed gone: List<T>.ForEach has been removed in Metro style apps. While the method seems simple it has a number of potential problems when the list gets mutated by the method passed to ForEach. Instead it is recommended that you simply use a foreach loop. Wes Haggard | .NET Framework Team (BCL) | http://blogs.msdn.com/b/bclteam/ Very … Read more

How to uninstall an app that another user installed?

My process above still works, but it simply gets around a race condition issue, where Windows Update (yes, oddly enough) is in charge of wiping out “staged packages.” According to Microsoft, the “other fix” – and I still consider this issue to be a bug – is: Cause of the problem: Windows Update (WU) downloads … Read more