Friday, April 6, 2012
AutoCAD 2013 and LiteHtml.dll
Thursday, May 19, 2011
Grandma's Apple Pie (as dictated by Mum)
Short Crust Pastry
Blend 125g butter, 125g plain flour and 125g self raising flour in a kitchen whiz.
Add 2 tablespoons of caster sugar and blend.
Add 1 egg yolk and combine.
Add 2-3 tablespoons of ice water (until the pastry almost combines)
Press pastry into a ball, then separate into 2/3 and 1/3 disks flattened out.
Wrap in plastic and chill for 60 minutes.
Apple Filling
Peel, core and slice 5-6 large Granny Smith Apples. Add 1 lemon, cut into quarters. Add 1/4 cup water (up to 1/2 cup).
Bring to boil and cook till softened. Add 1/2 cup sugar and stir until dissolved. Leave till cold.
Put pastry in tin and add cold apple, being sure to remove lemon. Cover with pastry. Brush the top with egg white, then sprinkle with caster sugar.
Cook at 220C for 10-15 minutes.
Turn oven down to 180C and cook for 25-20 minutes (ie, make the total oven time about 35 minutes).
Sunday, February 27, 2011
Samba NAS and error code -36
Saturday, November 27, 2010
Why are my zeroes behaving like ones?
Thursday, July 2, 2009
.NET corrupts heap when marshalling LPSTR
I've just spent the best part of a week trying to track down why my bridge from C# to C++ was working on Windows XP but crashing sporadically on Windows 7, and the answer is that .NET marshalling is trickier than you think for strings.
Essentially, I had this:
[DllImport("mydll.dll",CharSet=Ansi,CallingConvention=Cdecl)]
[MarshalAs(UnmanagedType.LPStr)]
private static extern String LookupCorrespondingString(Int32 key);
and in the DLL, I had
__declspec(dllexport) const char *LookupCorrespondingString(int key);
Whenever I called this, it would get all the way into my DLL, I could tell it was going to return a value, but during the return operation, it would crash. When I ran it in the debugger, I got output messages about how memory was being free'd into the wrong heap.
Eventually I found this article:
https://blogs.msdn.com/dsvc/archive/2009/06/22/troubleshooting-pinvoke-related-issues.aspx
which contained the useful quote (emphasis mine):
When a string buffer allocated by native code is marshaled to managed code, CLR Interop marshaller will allocate a managed string object and copy the contents of native buffer to the managed string object. Now in order to prevent a potential memory leak, CLR Interop Marshaller will try to free allocated native memory. It does so by calling CoTaskMemFree. The decision to call CoTaskMemFree is by-design. This can at times lead to crash, if memory was allocated by the called-native function using any API other than CoTaskMemAlloc family of API’s as custom allocators may allocate on different heaps.And there was the answer. .NET was freeing the block of memory I had passed to it to help me "prevent a potential leak". The problem being the lack of ability to communicate the 'const-ness' of the underlying DLL entry point's return value in the MarshalAs() attribute.
The solution was to declare the entry point differently:
[DllImport("mydll.dll",CharSet=Ansi,CallingConvention=Cdecl)]
private static extern IntPtr LookupCorrespondingString(Int32 key);
and then when I call it, do the marshalling explicitly.
String s = Marshal.PtrToStringAnsi( LookupCorrespondingString(k) );
Wednesday, May 13, 2009
Embedding .NET in an otherwise native application
Tuesday, March 31, 2009
".PDB files cannot be linked due to incompatible versions"
The problem is that the mspdbsrv.exe process (which Microsoft uses to create PDB files) does not always terminate after linking. If you have a mixed environment where you compile and link some modules with VC7.0 and then some with VC8.0, sometimes the 8.0 mspdbsrv.exe process hangs around and interferes with subsequent 7.0 compiles.