<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: win32 code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 03:12:02 GMT</pubDate>
    <description>DZone Snippets: win32 code</description>
    <item>
      <title>Using mmap to do a global search and replace on Windows</title>
      <link>http://snippets.dzone.com/posts/show/5487</link>
      <description>// Use win32-mmap to do a global search and replace on Windows&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32/mmap'&lt;br /&gt;require 'windows/msvcrt/buffer'&lt;br /&gt;include Windows::MSVCRT::Buffer&lt;br /&gt;&lt;br /&gt;Strlen = API.new('strlen', 'L', 'L', 'msvcrt')&lt;br /&gt;Strstr = API.new('strstr', 'LP', 'L', 'msvcrt')&lt;br /&gt;&lt;br /&gt;Dir["**/*.rb"].each{ |f|&lt;br /&gt;   p f&lt;br /&gt;   Win32::MMap.new(:file =&gt; f) do |addr|&lt;br /&gt;      old_str = 'some_old_string'&lt;br /&gt;      old_len = old_str.length&lt;br /&gt;      new_str = 'some_other_string'&lt;br /&gt;      new_len = new_str.length&lt;br /&gt;&lt;br /&gt;      ptr1 = ptr2 = ptr3 = Strstr.call(addr,old_str)&lt;br /&gt;&lt;br /&gt;      while ptr1 &amp;&amp; ptr1 != 0&lt;br /&gt;         ptr2 += new_len&lt;br /&gt;         ptr3 += old_len&lt;br /&gt;         memmove(ptr2, ptr3, 1 + Strlen.call(ptr3))&lt;br /&gt;         memcpy(ptr1, new_str, new_len)&lt;br /&gt;         ptr1 = ptr2 = ptr3 = Strstr.call(ptr2,old_str)&lt;br /&gt;      end&lt;br /&gt;   end&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 May 2008 04:14:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5487</guid>
      <author>djberg96 (Daniel Berger)</author>
    </item>
    <item>
      <title>test1</title>
      <link>http://snippets.dzone.com/posts/show/4867</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;printf("test");&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Dec 2007 14:37:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4867</guid>
      <author>flo (flo)</author>
    </item>
    <item>
      <title>Open/Creates a Base Key in the Registry</title>
      <link>http://snippets.dzone.com/posts/show/4524</link>
      <description>// open a Base Key in the registry&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;       public static RegistryKey GetKey(string baseKey)&lt;br /&gt;        {&lt;br /&gt;            RegistryKey key;&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                key = Registry.LocalMachine.OpenSubKey(baseKey, true);&lt;br /&gt;&lt;br /&gt;                if (key == null)&lt;br /&gt;                {&lt;br /&gt;                    key = Registry.LocalMachine.CreateSubKey(baseKey);&lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                {&lt;br /&gt;                    MessageBox.Show("Base key resolved");&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            catch (Exception e)&lt;br /&gt;            {&lt;br /&gt;                return null;&lt;br /&gt;            }&lt;br /&gt;            return key;&lt;br /&gt;        }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Sep 2007 11:58:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4524</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>Wallpaper.reg</title>
      <link>http://snippets.dzone.com/posts/show/3115</link>
      <description>&lt;code&gt;&lt;br /&gt;[HKEY_CURRENT_USER\Control Panel\Desktop]&lt;br /&gt;"Wallpaper"="C:\\wallpaper.bmp"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 09 Dec 2006 03:41:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3115</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
    <item>
      <title>Recover Master Boot Record</title>
      <link>http://snippets.dzone.com/posts/show/2798</link>
      <description>From http://www.trajano.net/2006/07/freedos-to-rescue.html:&lt;br /&gt;&lt;br /&gt;http://www.freedos.org/freedos/files/&lt;br /&gt;If you ever bust up your dual boot installation because you wanted to remove Linux on your laptop with no floppy drive. Like me a few minutes ago. Go grab the FreeDOS ISO image and burn it to your CD-RW media and boot from it.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Press Enter&lt;br /&gt;Type 2 (for safe mode)&lt;br /&gt;cd FREEDOS&lt;br /&gt;FDISK /MBR&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 08 Oct 2006 07:39:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2798</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
    <item>
      <title>Mongrel on Win32 as Service</title>
      <link>http://snippets.dzone.com/posts/show/1846</link>
      <description>Mongrel now has support for running as a Win32 service right out of the box. The support is still rough but works well enough that we decided to release it. You can thank Luis Lavena for working on this and making it so nice.&lt;br /&gt;&lt;br /&gt;After you do the gem install, find a Rails application you want to run and do:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ mongrel_rails_service install -n myapp -r c:\my\path\to\myapp -p 4000 -e production&lt;br /&gt;$ mongrel_rails_service start -n myapp&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now hit the port and poof, works. Stopping the app is just done with:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ mongrel_rails_service stop -n myapp&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;And, you can even set the CPU processor affinity for the service when yourun the install command. Can&#8217;t even do that on POSIX yet. Now that&#8217;s hot.&lt;br /&gt;&lt;br /&gt;If you run into an app that&#8217;s not running right, my suggestion is to run it with the regular mongrel_rails runner:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ cd c:\my\path\to\myapp&lt;br /&gt;$ mongrel_rails start -p 4500&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Since that will spit out error messages and stuff to the console. Use CTRL-Pause/Break to stop.&lt;br /&gt;</description>
      <pubDate>Wed, 05 Apr 2006 09:44:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1846</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
    <item>
      <title>Speech recognition</title>
      <link>http://snippets.dzone.com/posts/show/734</link>
      <description>The code is too long. I'd rather just make a &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/93025&gt;link&lt;/a&gt;.&lt;br /&gt;It uses MS Speech SDK 5.1 via COM.</description>
      <pubDate>Sat, 17 Sep 2005 06:26:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/734</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Text-to-speech</title>
      <link>http://snippets.dzone.com/posts/show/733</link>
      <description>&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; import win32com.client&lt;br /&gt;&gt;&gt;&gt; s = win32com.client.Dispatch("SAPI.SpVoice")&lt;br /&gt;&gt;&gt;&gt; s.Speak('Hello, how are you?')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;You need MS Speech SDK installed. See &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114216&gt;recipe&lt;/a&gt;.</description>
      <pubDate>Sat, 17 Sep 2005 06:16:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/733</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Get and set windows clipboard</title>
      <link>http://snippets.dzone.com/posts/show/724</link>
      <description>From June Kim's &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/150115&gt;recipe&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import win32clipboard as w &lt;br /&gt;import win32con&lt;br /&gt;&lt;br /&gt;def getText(): &lt;br /&gt;    w.OpenClipboard() &lt;br /&gt;    d=w.GetClipboardData(win32con.CF_TEXT) &lt;br /&gt;    w.CloseClipboard() &lt;br /&gt;    return d &lt;br /&gt; &lt;br /&gt;def setText(aType,aString): &lt;br /&gt;    w.OpenClipboard()&lt;br /&gt;    w.EmptyClipboard()&lt;br /&gt;    w.SetClipboardData(aType,aString) &lt;br /&gt;    w.CloseClipboard()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 16 Sep 2005 19:21:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/724</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Creating a share on windows</title>
      <link>http://snippets.dzone.com/posts/show/722</link>
      <description>Copied from John Nielson's &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303341&gt;recipe&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import win32net&lt;br /&gt;import win32netcon&lt;br /&gt;&lt;br /&gt;shinfo={}&lt;br /&gt;&lt;br /&gt;shinfo['netname']='python test'&lt;br /&gt;shinfo['type']=win32netcon.STYPE_DISKTREE&lt;br /&gt;shinfo['remark']='data files'&lt;br /&gt;shinfo['permissions']=0&lt;br /&gt;shinfo['max_uses']=-1&lt;br /&gt;shinfo['current_uses']=0&lt;br /&gt;shinfo['path']='c:\\my_data'&lt;br /&gt;shinfo['passwd']=''&lt;br /&gt;server='servername'&lt;br /&gt;&lt;br /&gt;win32net.NetShareAdd(server,2,shinfo)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 16 Sep 2005 17:44:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/722</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
