i want to embed a resource in a exe file using c#.
If i use c++ code it works well :
UpdateResource(hResource,RT_RCDATA,MAKEINTRESOURCE(104),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPVOID)text,FileSize);
c# code that i use :
IntPtr handle = BeginUpdateResource(this.NomeFileCryptato, false);
IntPtr fileptr = ToPtr(encrypted);
bool res = UpdateResource(handle, "RT_RCDATA", "104", 1040, fileptr, Convert.ToUInt32(encrypted.Length));
EndUpdateResource(handle, false);
Actualy, the c# code embed the resource in the exe file (let's call it a.exe) but if i embed the resource with c++, a.exe can read and extract, if i embed from c#, a.exe cannot.
any ideas?
this is the declaration for update resource in c# :
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData);
lpType and lpName are both strings and if i use UpdateResource(handle, "RT_RCDATA", "104", 1040, fileptr, Convert.ToUInt32(encrypted.Length)); the UpdateResource add the resource correctly to the exe.
The problem was on the c++. To reach the resource added from c# i have to use LPCSTR without the use of makeintresource macro.
LPCSTR nome = "CDATA";
LPCSTR tipo = "104";
hLibrary = LoadLibrary(this->filename);
hResource = FindResource(hLibrary, tipo, nome);
Thanks again for your time!