Skip to content

Clever Code

Showcase your best code, your most elegant solution, or your most hard fought subtle bug you've found and fixed

This category can be followed from the open social web via the handle clever-code@forum.codeproject.com

361 Topics 3.2k Posts
  • ASP.NET Subtle bug

    html csharp css asp-net sysadmin
    10
    0 Votes
    10 Posts
    3 Views
    M
    I can see your point for readability. I think it would be nicer if VS had better support for manipulating these though such as colour coding all instances of a selected parameter or allowing automatic re-numbering if you want to insert another parameter in the middle of a list (or delete an existing parameter)
  • 0 Votes
    1 Posts
    2 Views
    No one has replied
  • partitions problems in XP

    5
    0 Votes
    5 Posts
    3 Views
    D
    Anton Afanasyev wrote: Yeah, and it will sure work fine untill one of the 2+ drives you have dies. Especially the middle one. The way it's supposed to work you can add or remove single drives transparently and as long as you have >=2 drives and sufficient capacity it will shuffle the files around to maintain a mirrored copy of everything in the array. From what I understand one of the primary goals is to make a NAS with raidesque data mirroring that can be upgraded in capacity by users with relatively modest levels of technical skill. I'm fairly sure there're a few other things in it, but off the top of my head I don't recall what. I know they scrapped the idea of domains for the home because they weren't able to come up with a sufficiently idiotfriendly implementation along with the fact that vista only supports them in business/ultimate editions although that could be a chicken/egg issue. -- CleaKO The sad part about this instance is that none of the users ever said anything [about the problem]. Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
  • Type conversion strange bug

    help
    12
    0 Votes
    12 Posts
    4 Views
    L
    Seems to me you are running your program on original Pentium (remember - the one having problems with floating point operations) :laugh:
  • Two Days of Stress Later

    sysadmin help tutorial
    3
    0 Votes
    3 Posts
    1 Views
    T
    Sage advice. Wish i could :D ------------------------------- Carrier Bags - 21st Century Tumbleweed.
  • Batch Transactions

    database help sql-server sysadmin
    8
    0 Votes
    8 Posts
    4 Views
    C
    Mike Dimmick wrote: replication seems to go wrong Replication and MAPI access seem to destroy the BLOB field that's called "text-description" in WebDAV and "message.Body" in CdoEx. Whenever we move a public folder to another server, we loose some message bodies. The solution seems to be: Use only the content class "message" and nmessage type "IPM.Note". All other message classes get broken at random. ____________________________________ There is no proof for this sentence.
  • Microsoft Tetris

    game-dev help
    4
    0 Votes
    4 Posts
    4 Views
    M
    I used Windows 3 until about 13 years ago. I still have that Tetris game, my best score is -16,973
  • [in, out] variables - best not to reuse them! [moved]

    12
    0 Votes
    12 Posts
    3 Views
    P
    The beauty of C++ - there's always a nasty looking trick that one day will save your backus. We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP My first real C# project | Linkify!|FoldWithUs! | sighist
  • Datatype Misalignment Exception

    data-structures help question announcement
    12
    0 Votes
    12 Posts
    3 Views
    J
    Michael Dunn wrote: the this pointer is misaligned or garbage Tadaaa! Actually - both! ;) The SomeSharedResource pointer was never initialized in this particular scenario, so when checked for non-NULLness before calling SomeResource::Release, it's value was 0x3b3b3b3b, which is not only non-NULL but also clearly an unaligned pointer value. So the actual problem was not really that refCount_ was unaligned in some way, but the fact that this was unaligned. Had it been aligned, but unitialized, this problem would have been harder to find, since that likely just would have resulted in garbage and maybe later trashed data. -- Time you enjoy wasting is not wasted time - Bertrand Russel
  • Unexpected serialized object.

    help csharp json
    2
    0 Votes
    2 Posts
    3 Views
    P
    Have you fixed and tested this. The forum guidelines state that this is for bugs that you've found and fixed. Deja View - the feeling that you've seen this post before.
  • Bitmap Size

    graphics career
    20
    0 Votes
    20 Posts
    2 Views
    M
    It would help if you separated the Model/View in your head. The data is a 2 dimensional array of depth information. The view is the screen sized zoom the user is looking at. What you want is a bitmap extract function that can run at multiple zoom levels. There is a transition in the extraction algorithm at 1 to 1. It switches from multiple pixels per point to multiple points per pixel. You can probably insist on powers of 2 zoom levels. The big advantage of this is you only extract the bitmap you are actually going to display. My suggestion is that you use a semi-proprietary file form for the data, XML if file space is not an issue, something binary and compressed if it is. The format should allow at least one thumbnail to be attached. You can argue about what to attach, but an overall zoom to a small view (say 200x600) would probably me most useful for selecting files from a list. The file loader will create the needed array in memory (model), not an actual bitmap (view). Combining the model/view is a standard design error that routinely causes massive long term problem as you restrict the available metadata to what the view format will support.
  • Infinite Loop and Mouse Hooks [modified]

    help tutorial
    2
    0 Votes
    2 Posts
    3 Views
    J
    OK, here's the solution. It has to do with an undocumented behavior of the mouse hooks. Although MS doesn't tell us so, a mouse hook is triggered when PeekMessage or GetMessage finds a mouse message on the queue. MS would have us believe that this hook has nothing to do with picking up the message, but it's not true. Normally these mouse messages only hit the queue for a window one at a time, however, if the mouse is CLICKED then TWO end up on the queue for the window. In the code above, the first message, WM_LBUTTONDOWN, gets processed by the hook, which then calls PeekMessage in it's loop. PeekMessage finds WM_LBUTTONUP in the queue, not that we care because we are really just telling windows not to write us off. However, Windows DOES care, since this next message was a mouse message, and queues up another call for the mouse hook to complete as soon as the current one is done. After exiting the current hook function call, Windows calls it again, this time for WM_LBUTTONUP, however, WM_LBUTTONUP was never removed from the message queue, so it is STILL the message that PeekMessage will find, queueing up another call for the current function. This happens infinitely, causing an infinite loop that prevents any other code in the application from running, but without taking up much processor time, or locking the user out, since moving the mouse upsets the delicate balance required to make this work. It creates a great bug though when the user clicks...and waits...and waits...and waits, and when they finally get impatient and move the mouse, the screen comes up. The fix is very simple. We don't care what PeekMessage finds, if anything, so change the two NULL parameters to WM_QUIT. This will make PeekMessage ONLY serve up any WM_QUIT messages that it finds (which it will do anyway no matter what.) Since no mouse messages are served up, the bug goes away.
  • Overflowded!

    visual-studio data-structures debugging
    12
    0 Votes
    12 Posts
    5 Views
    X
    Just replace "get { return Bar; }" to "get { return this.mBar; }. I suggest you remove m from "mBar" and replace it with a "_":rolleyes: █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██
  • When 1 != 1

    com tools question
    7
    0 Votes
    7 Posts
    2 Views
    R
    One more note: This vod Surprise() { AxisID axisID; axisID.axisType = AxisZ; assert(axisID.axisType == AxisZ); // fails! (VC6, VC8) } becomes void Surprise() { AxisID axisID; axisID.axisType = AxisZ; assert(axisID.axisType == AxisZ); // fails! (VC6, VC8) } ROFLOLMFAO
  • Missing Partial Class Part

    help csharp question
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • Failing forward

    help windows-admin sales performance announcement
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • 0 Votes
    1 Posts
    1 Views
    No one has replied
  • Windows XP Error Reporting is slowing down

    5
    0 Votes
    5 Posts
    2 Views
    L
    :laugh::):omg::wtf:
  • A timely fix

    3
    0 Votes
    3 Posts
    3 Views
    M
    Shouln't you call it an untimely fix ? _____________________________________ Action without thought is not action Action without emotion is not life
  • Of paths and arcs

    csharp ruby css graphics sysadmin
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied