marshalling - c# using SetClipboardData fail with ERROR_INVALID_HANDLE -
when try set string clipboard native method setclipboarddata. fails , error code 6 error_invalid_handle getlasterror() method. can not find out how fails, here code:
string copymessage = "need copy clipboard"; const int gmem_movable = 0x0002; const int ghnd = gmem_movable; uint format; uint bytes; intptr hglobal = intptr.zero; format = cf_unicodetext; byte[] copymessagebytes = encoding.unicode.getbytes(copymessage + "\0"); // important: setclipboarddata requires memory acquired globalalloc using gmem_movable. hglobal = globalalloc(ghnd, (uintptr)copymessagebytes.length); if (hglobal == intptr.zero) { return false; } marshal.copy(copymessagebytes, 0, hglobal, copymessagebytes.length); if (setclipboarddata(format, hglobal).toint64() != 0) // code fails here { // important: setclipboarddata takes ownership of hglobal upon success. hglobal = intptr.zero; } else { return false; } i use marshal.copy(byte[] source, int startindex, intptr destination, int length) copy bytes hglobal , right? in case, dose must use native method copymemory() this? why?
thx
i found how fix it. because alloc memory globalalloc(), need call globallock() before copy data, need call globalunlock() after copy.
Comments
Post a Comment