Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 900 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
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 Offline OP
Serious User
Reconnoiter  Offline 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:

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
Code:
strcpy(input_str , final); //c-style

than ?

Re: inkey coy paste [Re: Reconnoiter] #449803
03/31/15 18:05
03/31/15 18:05
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
no.
Code:
char *temp = ...;

// Copy to an existing STRING
STRING *str;
str_cpy(str, temp);

// Creating a new STRING:
STRING *str = str_create(temp);

// Setting a TEXT member
// If no string is set (should be default case), create one
if((input_txt.pstring)[0] == NULL)
    (input_txt.pstring)[0] = str_create(temp);
else
    str_cpy((input_txt.pstring)[0], temp);



Visit my site: www.masterq32.de
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 Offline OP
Serious User
Reconnoiter  Offline 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):

Code:
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: Reconnoiter] #449864
04/01/15 18:05
04/01/15 18:05
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////

TEXT* input_txt=
{
	layer=31;
	pos_x=100;
	pos_y=100;
	strings=1;
	flags = TRANSLUCENT | SHOW;
}

void from_clipboard()
{
 
	STRING *temp="";
	STRING *final="";
	
	if(IsClipboardFormatAvailable(CF_OEMTEXT))//is this format available ?
	{
		if(OpenClipboard(hWnd))//open the clipboard
		{					
			HANDLE data=GetClipboardData(CF_OEMTEXT);
			if(data!=NULL)//got handle ?
			{
				temp=GlobalLock(data);//lock
				if(temp!=NULL)//got it ?
				{
					final=temp;	
				}
				GlobalUnlock(data);//unlock 
			}			
			CloseClipboard();//close clipboard
		}
	}
	
	if((input_txt.pstring)[0]==NULL)(input_txt.pstring)[0]=str_create(final);
	else str_cpy((input_txt.pstring)[0],final);

}

void to_clipboard(char *content)
{
 
   int len=str_len(content)*sizeof(char);
   if(len==0) return;//data was empty
	
	if(OpenClipboard(hWnd))//open the clipboar
	{
		if(EmptyClipboard())//emptied?
		{ 
			HANDLE mem=GlobalAlloc(GMEM_MOVEABLE,len+1);//alloc mem
			if(mem)//non zero ?
			{
				char* temp=GlobalLock(mem);
				memcpy(temp,content,len);
				if(!SetClipboardData(CF_OEMTEXT,mem))
				{
					GlobalFree(mem);
					CloseClipboard();
					return;
				}
				GlobalUnlock(mem);
				CloseClipboard();
			}
		}
	}
	   

}

void main()
{
 	warn_level=6;
	
	to_clipboard("hello this is a test");
	from_clipboard();
}



Compulsive compiler
Re: inkey coy paste [Re: Wjbender] #449872
04/01/15 19:10
04/01/15 19:10
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Ever Cool! Did you create that Wjbender?


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: inkey coy paste [Re: DLively] #449879
04/01/15 20:26
04/01/15 20:26
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
nah it's just a bunch of Windows functions


Compulsive compiler
Re: inkey coy paste [Re: Wjbender] #449883
04/01/15 20:58
04/01/15 20:58
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Pretty Sweet! Thanks for sharing this!


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
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 Offline
Expert
WretchedSid  Offline
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
W
Wjbender Offline
User
Wjbender  Offline
User
W

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
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
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
Page 2 of 3 1 2 3

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1