Thursday, August 27, 2009

Drag-and-Drop in C on Windows, the easy way

OK, yeasterday I published a post where I complained about the complexities of Drag-and-Drop in plain C on Windows, and how this was related to Object Orientation gone bad. Why do you need three or 4 objects, jsut to drag a string of text from one place to another?

Well, then, if you agree that this is outrageous, I have help for you now. I just published my plain C library that does just this. You simple Win32 C program need not worry about OLE or COM. About IDataObject or interfaces or any of that stuff. Just usse hardcore C, like all macho developers like myself do. You need my library though, and I admit I AM cheating a bit in it, but actually, it does the trick and it follows the rules, both from COM/OLE and Win32 points of views.

Now, to drag and receive a text string, you need my library and you need to call 4 plain C functions or so, nuthin' else: Init the library, register as a target for a drop, start dragging and cleanup as a target for a drop. Then you need to handle the drop itself of course, but this is easy enough.

So the help is now available on Sourceforge and there is the source for the library, a Visual Studio project for this, complete with a sample, and a full PDF document describing the whole thing.

So, happy hacking, and don't drag your feet!

5 comments: said...

Hi Anders, thanks for the library. It's quite convenient, and easily to follow to see what's happening under the hood.

Just one thing: I've found a bug when using the library in UNICODE mode.

The function CreateMyDropSourceText uses _tcslen to get the string length for GlobalAlloc. _tcslen returns the number of characters in the string, not the number of bytes. Consequently, in UNICODE mode, the GlobalAlloc call will allocate a buffer that is too small and lead to buffer overrun.

Also, CreateMyDropSourceText only uses CF_TEXT format; it doesn't have an option for CF_UNICODETEXT.

Because of these two factors, I suggest changing the function's "pText" argument from "LPCTSTR" to "LPCSTR". This will direct the caller to always use ANSI (8-bit) strings with CreateMyDropSourceText. Then, use strlen instead of _tcslen, and strcpy instead of _tcscpy.

marko said...

You may ask regardless of whether hole protection scope is required for all individuals that back the autos. The answer is that it will depend intensely on your scope. On the off chance that your consistent auto protection is arranged to pay off the financed sum completely, then there is no requirement for you to get hole insurance. auto title loans near for me

marko said...

On the off chance that you have credit issues of some kind you may have been denied an advance to purchase an auto by various loan specialists. With a specific end goal to guarantee that the right arrangements in terrible credit auto financing are made accessible to you, it is important to settle on the right choice about loan specialists you apply to. cash advance chicago

Jessica Arianna said...

Reviled is forearmed! So it is with payday credits. In case you appreciate what this affectionate of acclaim will amount you, you will be in a common position than cuff the slants and deficiencies of clearing on it. Therefore you will by and ample apperceive actually what arrant you allegation to pay aback to the payday beforehand affiliations. Check Cashing

musa ibrahim said...

The accumulated you advanced through these advances accompany with you to buy bike of any accomplish or model. You can additionally so far the base get to a bore attestant to bicycle, yet it cerebrum not be old than 5-6 years. An apprenticed abuttals of borrowers can administrate for these credits. There is no activity at all abstinent of absoluteness that the borrower is continuing through a abhorrent ceremony as a buyer. Cash Advance