-3

I want to watermark a textbox, and found several different ways of doing it, but one that I liked uses SendMessage and an external DLL. However, I think I heard somewhere that doing it this way can cause BSOD since it isn't managed. Is this true, or is it just hear-say.

http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx

private const uint ECM_FIRST = 0x1500;
private const uint EM_SETCUEBANNER = ECM_FIRST + 1;

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
Arlen Beiler
  • 15,336
  • 34
  • 92
  • 135
  • Unmanaged API may crash your program, but it won't cause BSOD. – Sorayuki Jun 01 '15 at 14:02
  • 4
    _"this way can cause BSOD since it isn't managed"_ - that's not how it works... that's not how any of this works. Please explain where you heard this and back your claim with believable sources or write it off as rumors. – CodeCaster Jun 01 '15 at 14:02
  • Thanks, edited, my question. @CodeCaster, feel free to leave an answer. – Arlen Beiler Jun 01 '15 at 14:05
  • 1
    Using direct Windows API calls introduces portability issues (e.g. porting to Mono). Most likely not a problem in your case, but worth noting. – Baldrick Jun 01 '15 at 14:16
  • FYI, .NET WinForms is entirely implemented on top of Windows API calls like that. – Lucas Trzesniewski Jun 01 '15 at 14:18
  • 1
    @Lucas: Yep, but there's a WinForms implementation for Mono which isn't... :) So as long as you don't call the Windows API directly from your own code, a lot of it can port. – Baldrick Jun 01 '15 at 14:20
  • @Baldrick, yes, that's why I said ".NET" in the comment :-) – Lucas Trzesniewski Jun 01 '15 at 14:22
  • 1
    @LucasTrzesniewski: As .NET is a standard, not an implementation, then I always understood that Mono and Microsoft versions are both '.NET'. Maybe I'm wrong. Hardly matters from the POV of this question anyway... :) – Baldrick Jun 01 '15 at 14:25

1 Answers1

0

The short answer is no. It won't cause a BSOD, although it could crash your program.

WinForms is basically built on top of Windows API calls, so when done right, custom API calls should work good as well.

One other thing to keep in mind is that if you do call the Windows API, it may create portability issues, such as when porting to Mono, as those DLLs will most likely not be available.

Arlen Beiler
  • 15,336
  • 34
  • 92
  • 135