Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,
How to use UpdateResource in c# with P/Invoke??
Ther's any other function that allow to update exe file in c# like UpdateResource??

I used google search but i can't found what i want??
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 19:58pm    
Not a good idea. .NET resources are different.
--SA

This function needs data returned by a couple of other functions in order to work. It'll update the resources in an .EXE file (with some restrictions), but it will NOT update the resources in the .EXE file that is currently running.

So, if you were looking to save data in your .EXE's own resources, you can't do it.

See the example of using it here[^].
 
Share this answer
 
Please have a look on this [link].

Signature of UpdateResource.

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

You might access this API like,

            IntPtr handleExe = BeginUpdateResource(exeFilePath, false);
            
            CultureInfo currentCulture = CultureInfo.CurrentCulture;
            int pid = ((ushort)currentCulture.LCID) & 0x3ff;
            int sid = ((ushort)currentCulture.LCID) >> 10;
            ushort languageID = (ushort)((((ushort)pid) << 10) | ((ushort)sid));

            GCHandle iconHandle = GCHandle.Alloc(resourceData, GCHandleType.Pinned);



Then you might call UpdateResource by sending those parameters.

If you want to know the explanation of each parameter you might see this [link].
 
Share this answer
 
v2
Comments
Md. Rashim Uddin 24-Aug-11 8:03am    
Is it solve your problem? Please lemme Know if not
Thanks,
Rashim

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900