Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# BeginUpdateResource

I would like to add a string resource to an executable file programmatically. Just for example purposes, let's say I am trying to add a string named "String SO" which holds the value of "stringVal"

If this helps anyone - if I were to do this through VS.net I could just right click on my Project => Resources => Add New String Resource etc..

I am using the following Win32 API's:

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

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool UpdateResource(IntPtr hUpdate, uint lpType, uint lpName, ushort wLanguage, byte[] lpData, uint cbData);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);

So, I have found a couple of pages online but none of them seem to help me in what I am trying to do. If any of you are able to find anything I would be very grateful.

Otherwise, I would greatly appreciate any snippets that may help. Thank you, Evan


1 Answers

There is a very helpful library for many resource-tasks at github.

Many classes and function do wrap those window-api-calls around UpdateResource(...), etc.

Hope that helps.

like image 102
ralf.w. Avatar answered Jun 11 '26 23:06

ralf.w.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!