G
Guest
I've copied an example of code for send a WM_COPYDATA to a unmanaged
application. I don't undenstand because is necessary allocate unmanaged
memory in double size of necessary : oCDS.cbData = (sScript.Length + 1) * 2
Why is necessary multiply per 2 ?
Is not sufficient allocate sScript.Length byte of memory ?
COPYDATASTRUCT oCDS = new COPYDATASTRUCT();
oCDS.cbData = (sScript.Length + 1) * 2;
oCDS.lpData = LocalAlloc(0x40, oCDS.cbData);
Marshal.Copy(sScript.ToCharArray(), 0, oCDS.lpData, sScript.Length);
oCDS.dwData = 1;
SendMessage(...)
LocalFree(oCDS.lpData);
application. I don't undenstand because is necessary allocate unmanaged
memory in double size of necessary : oCDS.cbData = (sScript.Length + 1) * 2
Why is necessary multiply per 2 ?
Is not sufficient allocate sScript.Length byte of memory ?
COPYDATASTRUCT oCDS = new COPYDATASTRUCT();
oCDS.cbData = (sScript.Length + 1) * 2;
oCDS.lpData = LocalAlloc(0x40, oCDS.cbData);
Marshal.Copy(sScript.ToCharArray(), 0, oCDS.lpData, sScript.Length);
oCDS.dwData = 1;
SendMessage(...)
LocalFree(oCDS.lpData);