Posts Tagged ‘C++’

One of the guys on #PowerShell in IRC was asking about how to get the contents of the clipboard in PowerShell, and after we had tried several different scripts, we realized that in Version 1, because PowerShell runs in an MTA thread, you cannot access the clipboard without creating a new thread (in STA mode). After I got done ranting, and pointing out that everyone needs to use PowerShell v2 (yeah, it’s still in CTP, so I was mostly kidding) in -STA mode … I whipped together the C# one liner and stuck it into a class with instructions for compiling, and figured I might as well share.

The code is below. There are two files: Clip.cs and Paste.cs … you probably only need Paste.cs, because Clip.exe is already included in Windows after Windows XP, but for the sake of completeness (and because it was just a few lines), I wrote them both.

To use them, you must compile them using Csc.exe, which is included as part of the .Net Framework. If it’s not already on your path, it’s in the folder for your most recent .Net Framework version (eg: C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe or C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe). All you have to do is run: csc Paste.cs and csc Clip.cs and you should end up with a Paste.exe and Clip.exe which you can use to copy and paste from the command-line… Read the rest of this entry »

To those of you who are not software developers: feel free to skip this post ;-)

A while ago I wrote a little class for calling console apps from a .Net application, and I’ve been using it in several of my apps (most notably in PoshConsole) and it works great, but since the only place I’ve really published it is in PoshConsole, I thought I’d write it up here, and share it with you …

Basically, it’s a slick invisible event-based wrapper around the Windows native console. What I mean is, it calls AllocConsole when it’s instantiated to create a native console, and hides the console window so it doesn’t show up. This allows you to run any console app you need to from within your app without having it popup a black window ;) Note this doesn’t let you run graphical consoles like EDIT.COM, but it can handle interactive apps like cmd.exe, batch files, or ftp.exe). All you really have to do is create one of my NativeConsole objects, handle its WriteOutputLine and WriteErrorLine events … and use its WriteInput method to send input or commands to the console app.

You can check out how it works in my WPF-based PoshConsole, and you can get the latest version of it from that project as well (it’s in \trunk\Huddled\Interop\NativeConsole.cs) but for now, here’s the single file source code, with a more liberal set of licenses than I allow for PoshConsole. Read the rest of this entry »

Well, Microsoft has released its free Visual C++ 2008 Feature Pack for download — including a major update to MFC and an implementation of TR1 which includes smart pointers, regular expressions, containers and better random number generators.

The update to MFC is a fairly major overhaul, and includes components which provide the L&F(Look And Feel) of IE, Office 2007 (including the ribbon bar), Visual Studio (including Visual Studio docking and autohide windows), with support for Vista themes, and on-the-fly customization of toolbars and menus, according to Somasegar. The list goes on, and it honestly left me feeling conflicted — I mean, now that MFC has joined us in the 21st century, I’m almost tempted to actually use it …

Search My Content