title: VB.NET UpdateResource is always capital and adds resource, not update
body: <p>I am wondering why my updateresource is not working. It is always capital, and does not update/replace the resource, only adds one.</p>
  
  <p>Here is my code in VB.NET</p>
  
  <pre><code>Imports System.Runtime.InteropServices
  
  Public Class Form1
  
  Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
      Dim strMiniConfig As String
      strMiniConfig = TextBox1.Text
  
      Dim encoder As New System.Text.UnicodeEncoding()
  
      WriteResource("UpdateMyRes.exe", encoder.GetBytes(strMiniConfig))
  
      MsgBox("Resources are now updated.", vbOKOnly + MsgBoxStyle.Information)
  
  End Sub
  
  
  &lt;DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)&gt; _
  Private Shared Function UpdateResource(ByVal hUpdate As IntPtr, ByVal lpType As String, ByVal lpName As String, ByVal wLanguage As UShort, ByVal lpData As IntPtr, ByVal cbData As UInteger) As Boolean
  End Function
  &lt;DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)&gt; _
  Private Shared Function BeginUpdateResource(ByVal pFileName As String, &lt;MarshalAs(UnmanagedType.Bool)&gt; ByVal bDeleteExistingResources As Boolean) As IntPtr
  End Function
  &lt;DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)&gt; _
  Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal fDiscard As Boolean) As Boolean
  End Function
  
  Public Function WriteResource(ByVal filename As String, ByVal bytes As Byte()) As Boolean
      Try
          Dim handle As IntPtr = BeginUpdateResource(filename, False)
          Dim file1 As Byte() = bytes
          Dim fileptr As IntPtr = ToPtr(file1)
          Dim res As Boolean = UpdateResource(handle, "RCData", "CONFIG", 1, fileptr, System.Convert.ToUInt16(file1.Length))
          EndUpdateResource(handle, False)
      Catch ex As Exception
          Return False
      End Try
      Return True
  
  End Function
  
  Private Function ToPtr(ByVal data As Object) As IntPtr
      Dim h As GCHandle = GCHandle.Alloc(data, GCHandleType.Pinned)
      Dim ptr As IntPtr
      Try
          ptr = h.AddrOfPinnedObject()
      Finally
          h.Free()
      End Try
      Return ptr
  
  End Function
  End Class
  </code></pre>
  
  <p>This should replace a resource from RCData\CONFIG but it always adds resource with name RCDATA\CONFIG ? Why is that? </p>
  
  <p>Here is the same code in C++:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>WCHAR * newD = L"I am updated resource at the RCData\CONFIG";
  HANDLE hUpdate = BeginUpdateResourceW(L"Stub.exe", false);
  UpdateResourceW(hUpdate, MAKEINTRESOURCEW(10), L"CONFIG", 1, newD, wcslen(newD)*2);
  EndUpdateResource(hUpdate, false);
  </code></pre>