Thoughts of a random geek

Tuesday, November 18, 2008

Windows Sockets

MSDN on winsock

CodeProject C++ skeleton using winsock

Of note: An application must call the WSACleanup function for every successful time the WSAStartup function is called. This means, for example, that if an application calls WSAStartup three times, it must call WSACleanup three times. The first two calls to WSACleanup do nothing except decrement an internal counter; the final WSACleanup call for the task does all necessary resource deallocation for the task.

Also: If you include windows.h and winsock2.h, you have to put winsock2 first. Otherwise, windows.h will include winsock.h and you'll get a plethora of redefinition errors from winsock2.h.

Inter-process communication in Windows

MSDN on the many ways to do IPC, including links to each.

Abridged version -
  • memory mapped files are fast, but need wrapped in a mutex and can't be used over a network
  • WM_COPYDATA message is useful if you have a message pump. Windows automagically shares the address space for you.
  • Mailslots can broadcast to multiple receiving processes and work on a network
  • Pipes are guaranteed two-way communication and work over a network
  • Sockets are platform independent

There's more, but I don't have experience with DDE/COM.

Here's an awesome codeproject page discussing multiple ways to inject your code into another process, including how to subclass a control (like the Windows Start button, in the example it switches the left and right mouse buttons). The page is extremely informative and uses some IPC techniques.

Monday, November 10, 2008

High-precision timing in Windows, cont.

Building on what I found earlier, here are some more attempts to make a high precision, high accuracy, high performance timer in Windows.

This link explains another timer, and provides BSD-licensed code.

ByteFusion makes a proprietary timer.

SourceForge has a project called fasttime, but it doesn't support Windows.

Fasttime has a sister project, TSC-I2, which has some nice details.

Here is the documentation for the Windows NTP client, w32tm, the Windows Time Service.

An MSDN blog indicates that the Windows Time Service is intended to keep sync only to the extent that Kerberos requires, and cannot maintain sync down to the second boundary.