0

I have an MFC application having a custom XML resource.

At some point I want to update the values in the XML tags/or whole XML file.

I am using following code:

UpdateResource(NULL ,_T("RT_RCDATA"), MAKEINTRESOURCE(IDR_XML), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPVOID)bytes, dwBytesWritten);

where bytes contains the new data for the file (replacing whole content of the file as couldn't get to a particular tag.)

But its not working and giving error-code 87 (ERROR_INVALID_PARAMETER) Also tried giving the current exe handle as first param in UpdateResource But it ofcourse returned Access Denied error.

So I am kinda stuck here and just wanna know is there an easy(or hard) way to update resources within the application? Any help would be appreciated.

foobar
  • 2,887
  • 2
  • 30
  • 55
  • 2
    Does it not surprise you that you don't get to specify the actual file name anywhere? Do you expect the OS to read your mind? The first parameter of `UpdateResource` can't be `NULL`, but a handle returned by `BeginUpdateResource` (and you should call `EndUpdateResource` when you are done). The second parameter should be `RT_RCDATA` (without quotes) - it's a named constant, not a string. – Igor Tandetnik May 10 '14 at 14:04
  • The exe to be changed is the exe itself. So if I give the exe name in BeginUpdateResource and use that handle , it will always return ACCESS DENIED. What else can I do? – foobar May 10 '14 at 14:08
  • 2
    The EXE can't update its own resources while its running. As to what else you could do - that rather depends on what you are trying to achieve. Your question looks suspiciously like an XY problem. What's the ultimate goal of the exercise? – Igor Tandetnik May 10 '14 at 14:12
  • Oh .. and is there no way to achieve that?? – foobar May 10 '14 at 14:13
  • 1
    Just want to save some data in the resource for later referencing. Lets say saving the LicenseKey once it is entered, and then checking it for validity everytime the application is run. What other approach can I try ? – foobar May 10 '14 at 14:17
  • 1
    Save the data in a separate file instead. – Igor Tandetnik May 10 '14 at 14:19
  • 1
    Or in the registry -- if a file, it should be not be located in the same folder as the exe, [ProgramData Folder](http://stackoverflow.com/a/11196213/1850797) is a good choice – Edward Clements May 11 '14 at 08:36
  • 3
    *"saving the LicenseKey once it is entered"* - So you are proposing a solution that makes it a no-brainer for hackers to get a fully unlocked application binary, ready for delivery through P2P networks? Maybe you should rethink this approach again. – IInspectable May 11 '14 at 13:40
  • License Key is machine specific and also will be encrypted, so it wont work on any other system. I know its still a lame approach, where else you think I can hide it locally? – foobar May 12 '14 at 06:15

0 Answers0