1

I need to edit the resources of a file in C++ using UpdateResource(), however I am unsure on how to go about getting the data for the 5th parameter (lpData).

I have no idea about how to create the data that needs to be provided for the function and the structure of the data, Can anybody provide guidance on how to go about getting/creating the data?

Ryan
  • 957
  • 5
  • 16
  • 34
  • UpdateResource(), from reading the docs, expects the raw binary data to be stored in the file as its lpData. LoadResource() seems to return said raw binary data. For a given resource type or field, you should be able to query what the LoadResource() return value looks like, which is I'd guess the format that UpdateResource() expects. For a more specific answer, you'd need to specify the lpType of the resource you are calling UpdateResource() on... there appear to be somewhere between a dozen and three dozen types of resource recognized? – Yakk - Adam Nevraumont Oct 27 '12 at 00:27
  • possible duplicate of [updating a string table with UpdateResource](http://stackoverflow.com/questions/14088057/updating-a-string-table-with-updateresource) – IInspectable Jan 11 '15 at 00:19

1 Answers1

1

Simply you can use:

wchar_t wszMyText[] = L"Some text";
HANDLE hUpdate = BeginUpdateResourceW( L"/path/to/file", FALSE );
// test return value.
BOOL res = UpdateResourceW( hUpdate, RT_STRING, L"MyResource", wszMyText,
    sizeof(wszMyText) - sizeof(wchar_t);
// check return value
EndUpdateResource( hUpdate, FALSE );
BigBoss
  • 6,904
  • 2
  • 23
  • 38
  • 1
    This is how you would replace any resource, except for strings. String resources are stored as string tables, with a specific layout (16-tuples of length prefixed strings). Details can be found at [updating a string table with UpdateResource](http://stackoverflow.com/a/14089163/1889329). – IInspectable Jan 10 '15 at 23:49
  • @IInspectable thank you for your comment and sharing of knowledge – BigBoss Jan 15 '15 at 15:23