Friday, April 15, 2016
Object Linking and Embedding Database
Recently, I've been messing with a database API I've never used directly before, even though I've been using it all the time. I'm talking about OLE DB, the interface behind ActiveX Data Objects (ADO).
MurmurHash in Transact-SQL
UPDATE: it's now a Gist.
UPDATE: now in Pascal too.
UPDATE: now for MySQL too.
Sometimes, one needs an intermediate strength hash. Something less collision prone than CRC32 or Adler-32, but smaller and less costly than MDx or SHAxxx. My favorite for a while has been MurmurHash64 - it produces a 64-bit value, just the right size to fit into a scalar variable in a C program, or a bigint database field.
UPDATE: now in Pascal too.
UPDATE: now for MySQL too.
Sometimes, one needs an intermediate strength hash. Something less collision prone than CRC32 or Adler-32, but smaller and less costly than MDx or SHAxxx. My favorite for a while has been MurmurHash64 - it produces a 64-bit value, just the right size to fit into a scalar variable in a C program, or a bigint database field.
Sunday, August 23, 2015
Pointer to a pointer to a pointer
I never thought I'd ever use the datatype void**** in a real project. Yet I did. That's the datatype of a pointer to a smart pointer to a COM object, which contains a pointer to the virtual function table, which is an array of function pointers.
Friday, August 14, 2015
Lack of a typelib is not a security fault
Amazing discovery of the day: Microsoft Word pops up a security prompt for a perfectly good macro if a reference to a typelib can't be resolved.
Tuesday, July 7, 2015
Abusing operator overloading for expression building
Sharepoint lists have a built-in SOAP API. In order to query a list, one has to build a query in XML, along the following lines:
<And><Eq><FieldRef Name="ID"/><Value>100</Value></Eq><NotNull><FieldRef Name="Name"/></NotNull></And>
Those strings are hard to follow, and building them is error prone. To the rescue comes operator overloading in C#. The idea is: field names are wrapped in class instances, comparison between those and numbers/strings produces a condition object, AND/OR between those produces compound condition objects, on the final stage you serialize that chain into an XML string.
The only caveat is, C# doesn't allow for && and || overloading, so we have to overload the bitwize operators & and | instead. The precedence is still what one would expect - AND before OR.
With that in place, the expression above can be written like that:
CAMLField f_ID = F("ID"), f_Name = F("Name");
(f_ID == 100 & f_Name.NotNull).ToString();
<And><Eq><FieldRef Name="ID"/><Value>100</Value></Eq><NotNull><FieldRef Name="Name"/></NotNull></And>
Those strings are hard to follow, and building them is error prone. To the rescue comes operator overloading in C#. The idea is: field names are wrapped in class instances, comparison between those and numbers/strings produces a condition object, AND/OR between those produces compound condition objects, on the final stage you serialize that chain into an XML string.
The only caveat is, C# doesn't allow for && and || overloading, so we have to overload the bitwize operators & and | instead. The precedence is still what one would expect - AND before OR.
With that in place, the expression above can be written like that:
CAMLField f_ID = F("ID"), f_Name = F("Name");
(f_ID == 100 & f_Name.NotNull).ToString();
Wednesday, January 14, 2015
Windows Phone vs. CE legacy
The Core Connectivity API totally works for Windows Phone 8.
They've changed CLSIDs of all classes and IIDs of all interfaces, but the new ones can be fairly easily seen in the registry. There are several new interfaces (ICcConnection2/3/4, notably) that make more sense for the Windows Phone security model. There's no arbitrary file/registry access that I can see (those methods return E_ACCESSDENIED), but some methods still work.
This new CoreCon has version numbers 10/11/12, which probably corresponds to Visual Studio 10/12/13 that it comes with. The DLLs are under C:\Program Files (x86)\Common Files\microsoft shared\Phone Tools\CoreCon\12.0\Bin. Most amazingly, the main DLL - ConMan2.dll - has debug symbols on Microsoft Symbol Server. Poking around it in a debugger or in a disassembler is a pleasure, considering.
Let's see how far this takes me. The LaunchApplication() method works, but I wonder what rights in the filesystem do I have...
They've changed CLSIDs of all classes and IIDs of all interfaces, but the new ones can be fairly easily seen in the registry. There are several new interfaces (ICcConnection2/3/4, notably) that make more sense for the Windows Phone security model. There's no arbitrary file/registry access that I can see (those methods return E_ACCESSDENIED), but some methods still work.
This new CoreCon has version numbers 10/11/12, which probably corresponds to Visual Studio 10/12/13 that it comes with. The DLLs are under C:\Program Files (x86)\Common Files\microsoft shared\Phone Tools\CoreCon\12.0\Bin. Most amazingly, the main DLL - ConMan2.dll - has debug symbols on Microsoft Symbol Server. Poking around it in a debugger or in a disassembler is a pleasure, considering.
Let's see how far this takes me. The LaunchApplication() method works, but I wonder what rights in the filesystem do I have...
Saturday, September 27, 2014
Some knowledge deserves to be spread
Upgraded my motherboard recently. With Windows, it's always a gamble. In recent versions, it often just works - Windows boots, some hardware doesn't work but once you install all the OEM drivers, it does.
In my case, not so much. After the hardware swap, Windows booted straight into the blue screen of death. Here's what helped: I booted into recovery mode, downloaded all OEM drivers on a different machine, copied them to a thumb drive, and ran the following command on the recovery console's command line:
dism /image:c:\ /add-driver /Driver:X:\ /recurse
Where C: is the Windows drive, and X: was the thumb drive. And voilĂ , Windows booted up on the next attempt.
Helpful idea found here. Spreading the knowledge because it deserves to be spread.
In my case, not so much. After the hardware swap, Windows booted straight into the blue screen of death. Here's what helped: I booted into recovery mode, downloaded all OEM drivers on a different machine, copied them to a thumb drive, and ran the following command on the recovery console's command line:
dism /image:c:\ /add-driver /Driver:X:\ /recurse
Where C: is the Windows drive, and X: was the thumb drive. And voilĂ , Windows booted up on the next attempt.
Helpful idea found here. Spreading the knowledge because it deserves to be spread.
Subscribe to:
Posts (Atom)