|
Re: inkey coy paste
[Re: Reconnoiter]
#449730
03/30/15 13:16
03/30/15 13:16
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////
function main()
{
vec_set(screen_size,vector(800,400,0));
vec_set(screen_color,vector(50,1,1)); // dark blue
vec_set(sky_color,vector(50,1,1)); // dark blue
video_window(NULL,NULL,0,"My New Game");
d3d_antialias = 1;
shadow_stencil = 3;
level_load("");
vec_set(camera.x,vector(-250,0,50));
vec_set(camera.pan,vector(0,-15,0));
char *text="";
if(OpenClipboard(NULL))
{
HANDLE data=GetClipboardData(CF_OEMTEXT);
if(data!=NULL)
{
text=GlobalLock(data);
GlobalUnlock(data);
}
CloseClipboard();
}
printf("%s",text);
}
something like this and
#include <acknex.h>
#include <default.c>
#include <windows.h>
function main()
{
level_load("");
STRING *text="";
if(OpenClipboard(NULL))
{
text=GetClipboardData(CF_OEMTEXT);
CloseClipboard();
}
printf("%s",text);
sys_exit("");
}
this wil work to0,but i think locking is safer?
Compulsive compiler
|
|
|
Re: inkey coy paste
[Re: MasterQ32]
#449781
03/31/15 11:44
03/31/15 11:44
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////
void main()
{
level_load("");
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
}
}
printf("%s",final);
sys_exit("");
}
so the best would be something like this , locking to prevent it being changed by other app's during the time your accesing it , right CF_OEMTEXT is for OEM caracter set. CF_TEXT format is said to be for ANSI text both CF_TEXT and CF_OEMTEXT ends each line with a carriage return/linefeed combination, and the end is signalled by a null caracter ...(from old c++ help documentation) . but they convert as needed if I understood correct
Last edited by Wjbender; 03/31/15 11:54.
Compulsive compiler
|
|
|
Re: inkey coy paste
[Re: Wjbender]
#449783
03/31/15 12:05
03/31/15 12:05
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
i haven't tried your latest posted code yet but with the following I got an Error E1516: Invalid memory area, named CAT in the error message. Maybe cause it pastes beyond the string length?
function inkey_paste()
{
if(inkey_active)
{
char *text="";
if(OpenClipboard(NULL))
{
HANDLE data=GetClipboardData(CF_OEMTEXT);
if(data!=NULL)
{
text=GlobalLock(data);
GlobalUnlock(data);
}
CloseClipboard();
}
str_cat((input_txt.pstring)[0], text);
reset(inkeyoptions_pan, SHOW);
}
}
The input text just incase:
TEXT* input_txt =
{
layer = 31;
font = calibri18;
strings = 1;
}
|
|
|
Re: inkey coy paste
[Re: Reconnoiter]
#449785
03/31/15 13:32
03/31/15 13:32
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
///////////////////////////////
#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 main()
{
warn_level=6;
char *temp="";
char *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
}
}
str_cpy((input_txt.pstring)[0],"");
str_cat((input_txt.pstring)[0],final);
//printf("%s",_chr((input_txt.pstring)[0]) );
}
looked fine for me , I filled the pointer with str_cpy before using it ..
Compulsive compiler
|
|
|
Re: inkey coy paste
[Re: Reconnoiter]
#449797
03/31/15 16:31
03/31/15 16:31
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
your pointer is invalid! final points to some invalid memory as soon as you call Unlock!
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////
void main()
{
level_load("");
STRING *temp="";
char final[256]; // max length
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 ?
{
// Copy here, don't use reference
// Also use strcpy and not str_cpy
// as we work with c-strings, not
// Lite-C STRINGS
strcpy(final, temp;)
}
GlobalUnlock(data);//unlock
}
CloseClipboard();//close clipboard
}
}
printf("%s",final);
sys_exit("");
}
|
|
|
Re: inkey coy paste
[Re: MasterQ32]
#449799
03/31/15 16:37
03/31/15 16:37
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
I don't know what's up , I have put the code into a while loop , copied text randomly for an extended period of time , i cannot find the error you get ..
good luck though.
edit : aah master to the rescue !
Last edited by Wjbender; 03/31/15 16:37.
Compulsive compiler
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|