title: VB.NET compatible sendmessage and sendmessagetimeout APIs
body: <p>Basically: I would like a sendmessage and sendmessagetimeout API for VB.NET that others have used and know works.</p>
  
  <p>I need an API for sendmessage and sendmessagetimeout for my VB .net application.  I have searched quite a bit, and everything I find doesn't seem to work: either the message just doesnt seem to be sent, or the message appears to be sent with the msg parameter always 0, and the wparam setting as what I enter for the msg setting.  Pinvoke's also always seems to throw an AccessViolationException for I have no idea what reason.  I tried playing around with maybe just where I put the variable, but unsurprisingly, there is not a simple logical switch of the variables.</p>
  
  <p>I have tried pinvoke's:</p>
  
  <pre><code>&lt;DllImport("user32.dll", SetLastError:=True)&gt; _
  Public Shared Function SendMessageTimeout(ByVal windowHandle As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal flags As SendMessageTimeoutFlags, ByVal timeout As Integer, ByRef result As IntPtr) As IntPtr
  End Function
  </code></pre>
  
  <p>and allapi's:</p>
  
  <pre><code>Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As String, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
  </code></pre>
  
  <p>among others, and they just dont seem to work.</p>
  
  <p>So I would like to know of whatever APIS for sendmessage and/or sendmessagetimeout you know of that work! If there just aren't correct APIs for VB.net for these functions, what alternative functions that I could use to accomplish the same task as those 2?</p>
  
  <p>Thank you in advance for any information you have :)</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>alternatively I may be sending the message incorrectly, so just to make sure that shouldn't be the issue:</p>
  
  <p>I want to send WM_WININICHANGE, so I am using: </p>
  
  <ul>
  <li>hwnd = HWND_BROADCAST = 0xffff = 65535 </li>
  <li>msg = WM_WININICHANGE = 0x001A = 26</li>
  <li>wparam and lparam of 0 </li>
  </ul>
  
  <p>but I have tried with other values for wparam and lparam with no difference usually. when trying sendmessagetimeout, I also use: </p>
  
  <ul>
  <li>flags = SMTO_ABORTIFHUNG = 2</li>
  <li>timeout = 1000 = 1 second</li>
  <li>then 0 for result.</li>
  </ul>