0

I want to create custom windows form control that will be derived from existing winform controls. For e.g. TextBoxEx will derive from System.Windows.Forms.TextBox. These new custom controls will change the look and feel and will add some extra capabilities to the existing control. This will be done by making appropriate win32 API calls.

I want to ensure that the developed custom controls work for both 32bit and 64bit platform. I would like to know the best way of achieving it on the basis of experiences (if any) of yours.

Anand Patel
  • 6,031
  • 11
  • 48
  • 67

1 Answers1

1

You don't have to do anything special. The underlying Windows API is the same irrespective of whether you are on 32 or 64 bit.

Data types that hold pointer sized things, e.g. window handles, float between 32 and 64 bit depending on which platform is targeted. For that reason they are declared as IntPtr for P/Invoke. So long as you get that right, your code will work on both platforms.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I understand that it will bind to the correct dll. For e.g. if I am using user32.dll, it will bind to 32 bit version of it on 32 bit platform and 64 bit version if is executing on 64 bit platform. But there are win32 API like SetWindowLong32 and SetWindowLongPtr64 in user32.dll. I need to make a choice in the code from those two API depending on what platforms are supported. Please advice. – Anand Patel Mar 18 '11 at 12:33
  • No, that API is called SetWindowLongPtr on both 32 and 64. There are practically no differences between the APIs. – David Heffernan Mar 18 '11 at 12:47
  • Initially I was having same impression, but see this: http://stackoverflow.com/questions/3343724/how-do-i-pinvoke-to-getwindowlongptr-and-setwindowlongptr-on-32-bit-platforms – Anand Patel Mar 18 '11 at 12:57
  • OK, that's right, there is no Ptr version in 32 bit DLLs. So this is one of the very few exceptions. You can just use Hans' code from that question, and a matching one for SetWindowLong. You won't come across much else like this. – David Heffernan Mar 18 '11 at 13:01
  • If there are just few such exceptions, then it can be dealt in the code - the way Hans (http://stackoverflow.com/questions/3343724/how-do-i-pinvoke-to-getwindowlongptr-and-setwindowlongptr-on-32-bit-platforms) has suggested. Thanks David. I have marked your response as the answer. – Anand Patel Mar 18 '11 at 13:08
  • @Anand Thanks. There really are practically no exceptions. You would have found this one when you tried to run it because there would have been a missing import. You need to consult MSDN for each API call. Have the SDK C header files at hand for any quirks. Really, it's a remarkably simple transition from 32 to 64 bit! – David Heffernan Mar 18 '11 at 13:22