BeginUpdateResource (kernel32)
Last changed: tsahi-217.132.117.209

.
Summary

C# Signature:

[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr BeginUpdateResource(string pFileName,
   [MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources);

VB.NET Signature:

<DllImport("kernel32.dll", SetLastError := False)> _
    Public Shared Function BeginUpdateResource(ByVal pFileName As String, _
    <MarshalAs(UnmanagedType.Bool)> ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function

User-Defined Types:

None.

Notes:

calls SetLastError. the last error can be retrieved with Marshal.GetLastWin32Error().

Tips & Tricks:

Please add some!

Sample Code:

internal void DelFile(ArrayList fileNames) {
   IntPtr hResource = BeginUpdateResource(mFileName, false);
   if (hResource.ToInt32() == 0) {
     throw new Win32Exception(Marshal.GetLastWin32Error());
   }
   foreach (String fileName in fileNames) {
     if (UpdateResource(hResource, "FILE", fileName,
       MakeLangId(LANG_ENGLISH, SUBLANG_ENGLISH_US), null, 0) == false) {
       throw new Win32Exception(Marshal.GetLastWin32Error());
     }
   }
   if (EndUpdateResource(hResource, false) == false) {
     throw new Win32Exception(Marshal.GetLastWin32Error());
   }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation