The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘C# 3.0’ Category

.NET/C#: open source Nikon SDK C# Wrapper project at SourceForge.net

Posted by jpluimers on 2014/06/26

Interesting: about a year and a half ago, the Nikon SDK C# wrapper project started ad sourceforge.

Basically, it allows you to integrate the operation of your Nikon DSLR into your .NET projects.

It has some very interesting features:

  • Control your Nikon DSLR via USB
  • Capture Jpeg and Raw images directly to system memory
  • Receive ‘Live View’ images
  • Record Video
  • Query and change camera settings (Exposure, Aperture, ISO, etc.)
  • And much more…

Downloads: Nikon SDK C# Wrapper – Browse Files at SourceForge.net.

–jeroen

via: Nikon SDK C# Wrapper | Free Security & Utilities software downloads at SourceForge.net.

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

.NET uses banker’s rounding as default as it follows IEEE 754 (via: Stack Overflow)

Posted by jpluimers on 2014/05/08

It is almost 3 years that Ostemar wrote an interesting answer on Stack Overflow to the question

Why does .NET use banker’s rounding as default? – Stack Overflow.

Few people (even many programmers don’t!) know about rounding and how it can influence software, let alone what bankers rounding does so lets set a few things straight first.

Rounding matters. Depending on the kinds of software you write, it matters a little, or a lot.

For instance, in these categories, it can matter an awful lot:

  • Financial applications
  • Statistical applications

Bankers rounding means rounding half even. Which means that #.5 will round to the even number closest to #.

In bankers rounding, 1.5 rounds to 2, 3.5 to 4 as does 4.5, -1.5 rounds to -2, -3.5 to -4 as does -4.5.

This is called “unbiased” because for reasonable distributions of y values, the expected (average) value of the rounded numbers is the same as that of the original numbers.

This is contrary to what the majority of people are accustomed to: Round half away from zero is taught in most countries (even for the Dutch, despite the alias “Dutch Rounding” for round half to even).

Round half away from zero rounds 1.5 rounds to 2, 3.5 to 4 and 4.5 to 5. Negative numbers round like this: -1.5 rounds to -2, -3.5 to -4 as does -4.5 to -5.

This is only free of overall bias if the original numbers are positive or negative with equal probability.

In short, .NET uses bankers rounding because it follows the IEEE 754 rounding rules.

This was his answer: Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET CF, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | 3 Comments »

In C#, given a DateTime object, how do I get a ISO8601 date in string format? – Stack Overflow

Posted by jpluimers on 2014/04/22

The first bulleted link below has been living in my drafts like forever (i.e. somewhere since mid June 2009), so time to write a bit about ISO 8601 and .NET.

First a few links about converting a DateTime into ISO 8601 string format:

Some solutions use the “K” as a time zone specifier. At first, I couldn’t find any documentation for it, not even Google Search for Google Search for “ssK” DateTime ToString returns anything useful.

Later on, I found The “K” Custom Format Specifier in Custom Date and Time Format Strings.

So my preferred solutions for me are these:

  • System.DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssK");
  • System.DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssK");

I avoid these:

  • System.DateTime.Now.ToString("o");
    because it gets you too many digits in the second fracion.
  • System.DateTime.Now.ToUniversalTime().ToString("s") + "Z";
    because it is less clear what it does (might be resolved with a comment).

–jeroen

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, ISO 8601, Software Development | 1 Comment »

.net/C# – Serialize into an XML Fragment – not XML Document – Stack Overflow

Posted by jpluimers on 2014/04/17

Thanks User Andrew Hare – Stack Overflow for answering this on Stack Overflow.

I’m pretty sure it works in all .NET and C# versions starting with 2.0.

Here is a hack-ish way to do it without having to load the entire output string into an XmlDocument: Read the rest of this entry »

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

c# – Is there a library that gets the media type and subtype out of a HttpWebResponse/WebResponse ContentType? – Stack Overflow

Posted by jpluimers on 2014/04/16

Just asked this on SO: C# – Is there a library that gets the media type and subtype out of a HttpWebResponse/WebResponse ContentType?.

Anyone here or at G+ that has a hint?

The [WayBack] ContentType property of [WayBack] (Http)WebResponse [WayBack] maps to the HTTP/1.1 [WayBack] Content-Type which is a [WayBack] Media-Type that contains a type/subtype optionally followed by parameters which are [WayBack] attribute=value pairs.

I’m mainly interested in the type/subtype and the [WayBack] charset parameter.

The charset is mapped from [WayBack] HttpWebRequest.CharacterSet.

Is there a library that just retrieves the media type/subtype of the [WayBack] ContentType?

–jeroen

via: [WayBack] c# – Is there a library that gets the media type and subtype out of a HttpWebResponse/WebResponse ContentType? – Stack Overflow.

Posted in .NET, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio 2013, Visual Studio and tools | Leave a Comment »

Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies – Rick Strahl’s Web Log

Posted by jpluimers on 2014/04/15

Reminder to self: for HttpWebRequest make sure you have your proxy setup correctly.

Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies – Rick Strahl’s Web Log.

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Fiddler, Software Development, Visual Studio 11, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, Web Development | Leave a Comment »

.NET UI Automation examples: The managed way to retrieve text under the cursor (mouse pointer) (via: The Old New Thing)

Posted by jpluimers on 2014/04/10

Some interesting UI Automation examples: The managed way to retrieve text under the cursor (mouse pointer).

  • find the text under the mouse cursor
  • run a the calc command
  • showing automation properties under the mouse cursor

–jeroen

via: The managed way to retrieve text under the cursor (mouse pointer) – The Old New Thing – Site Home – MSDN Blogs.

Posted in .NET, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

The C language specification describes an abstract computer, not a real one – The Old New Thing – Site Home – MSDN Blogs

Posted by jpluimers on 2014/04/09

Interesting read:

The C language specification describes an abstract computer, not a real one – The Old New Thing – Site Home – MSDN Blogs.

In other words: any language that merges null behaviour in the underlying storage will have a problem somwehere.

So if you want to have true nullable types, your null flag should be stored outside the underlying storage.

The .NET framework 2 and up, most database management systems and many other environment support that.

But most languages don’t support it for pointer types. So there will be portions of address spaces either inaccessible, or only accessible when skipping the null pointer checks.

Note that the thread above contains some very interesting bits, for instance this one:

Matt 28 Mar 2013 5:58 PM #

@MarkY “Dereferencing null is undefined?  Cool!  I thought it was guaranteed to crash, just like a false assertion or something.  So crashing is the OS guarantee, not the language guarantee apparently.”

Nope. It’s not an OS guarantee either. The OS won’t ever normally allocate memory at address zero, but there’s nothing to stop you telling it to. Try doing “VirtualAlloc(1, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)” on your pre-Windows8 machine.

In fact, this is the reason why null-dereferences in kernel mode are often exploitable as elevation of privilege attacks. The null-page is mappable and within the user-addressable region of memory, so if the kernel dereferences a null pointer, it reads attacker controllable data.

And btw, this is the reason why on Linux and Windows8+ you can’t map the null-page.

–jeroen

via: The C language specification describes an abstract computer, not a real one – The Old New Thing – Site Home – MSDN Blogs.

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Borland C++, Borland Pascal, C, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, C++ Builder, Database Development, Delphi, Development, Pascal, Quick Pascal, Software Development, Turbo Pascal, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 8.0, VB.NET 9.0 | Leave a Comment »

Getting Microsoft Product Keys back from the registry (via StackOverflow and various other sources)

Posted by jpluimers on 2014/04/02

Every once in a while, someone hoses their computer far enough that it has to be reinstalled, but the original Microsoft product keys are misplaced, and some creepy anti-virus tool disallows the running of standard product key recovery tools like nirsoft’s.

Well, there is enough sourcecode that does recover it, just look for any of these strings:

Some hits:

The below full executables can trigger a virus warning (ordered from less often to most often):

–jeroen

 

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, CommandLine, Delphi, Development, PowerShell, Software Development | Leave a Comment »

WinForms Container Controls 5: FlowLayoutPanel

Posted by jpluimers on 2014/03/24

When using a FlowLauyoutPanel, I always forget on which control the FlowBreak design time property / SetFlowBreak run time method operates.

Then I always end up writing a short demo program like Container Controls 5: FlowLayoutPanel.

It operates after the control on which you set it.

It is like text in a Word Processor: it breaks after the place where you set the break. Read the rest of this entry »

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development, WinForms | Leave a Comment »