3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: inkey coy paste
[Re: Wjbender]
#449800
03/31/15 17:24
03/31/15 17:24
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hi, I managed to got the error 1 more time but this time it said STR instead of CAT (prob. cause I am using str_cpy now). My code is the same as Master32q's except I added a str_cpy after the c-style strcpy cause I want to copy the result of 'final' to the (input_txt.pstring)[0]. I think str_cpy line creates the error. Here's my code:
function inkey_paste()
{
if(inkey_active)
{
STRING *temp="";
char final[256]; // max length
if (IsClipboardFormatAvailable(CF_OEMTEXT)) //is the format available
{
if (OpenClipboard(hWnd)) //open the clipboard
{
HANDLE data = GetClipboardData(CF_OEMTEXT);
if (data != NULL)
{
temp = GlobalLock(data); //lock
if (temp != NULL) //got it?
{
strcpy(final, temp); //c-style string
////strcpy((input_txt.pstring)[0], final); //instand crash
str_cpy((input_txt.pstring)[0], final); //mem crash I think
}
GlobalUnlock(data); //unlock
}
CloseClipboard(); //close clipboard
}
}
reset(inkeycommands_pan, SHOW);
}
}
Perhaps I should replace (input_txt.pstring)[0] with input_str and just do
strcpy(input_str , final); //c-style
than ?
|
|
|
Re: inkey coy paste
[Re: MasterQ32]
#449839
04/01/15 12:49
04/01/15 12:49
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
It seems to work perfectly now, tnx Masterq32. Can I ask for 1 more thing?; I am also trying to add a copy to clipboard function, but I don't really understand what to do exactly after emptying the clipboard (something with first allocating memory than using SetClipboardData):
function inkey_copy()
{
if(inkey_active)
{
STRING *temp="";
char final[256]; // max length
if (IsClipboardFormatAvailable(CF_OEMTEXT)) //is the format available
{
if (OpenClipboard(hWnd)) //open the clipboard
{
EmptyClipboard(); //empty clipboard
..... ?
CloseClipboard(); //close clipboard
}
}
reset(inkeycommands_pan, SHOW);
}
}
|
|
|
Re: inkey coy paste
[Re: DLively]
#449879
04/01/15 20:26
04/01/15 20:26
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
nah it's just a bunch of Windows functions
Compulsive compiler
|
|
|
Re: inkey coy paste
[Re: DLively]
#449885
04/01/15 21:07
04/01/15 21:07
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
@Wbjender: You are releasing a lock that is used to grant exclusive access to data that you use afterwards! Ie, you are race conditioning it all up in there.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: inkey coy paste
[Re: WretchedSid]
#449887
04/01/15 21:17
04/01/15 21:17
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
ofcourse I usually screw something up somewhere , what's the point of flawless code lol
https://msdn.microsoft.com/en-us/library/ms649016(VS.85).aspx#_win32_Copying_Information_to_the_Clipboard
I never used the clipboard but studying msdn example will help though , to whom needs it
Compulsive compiler
|
|
|
Re: inkey coy paste
[Re: Wjbender]
#449904
04/02/15 09:06
04/02/15 09:06
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
void to_clipboard(char *content)
{
int len=str_len(content)*sizeof(char);
if(len==0) return;//data was empty
if(OpenClipboard(hWnd))//open the clipboard
{
if(EmptyClipboard())//emptied?
{
HANDLE mem=GlobalAlloc(GMEM_MOVEABLE,len+1);//alloc mem
if(mem)//non zero ?
{
char* temp=GlobalLock(mem);
memcpy(temp,content,len);
GlobalUnlock(mem);
SetClipboardData(CF_OEMTEXT,mem);
}
}
CloseClipboard();
}
}
this follows the msdn example in flow , better ?
Compulsive compiler
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|