Writing text at a pre defined coordinate into the stdout.

If you are a PHP newbie or a WinBinder novice, this is the right place for you.

Moderator: rubem

Postby frantik » Thu Oct 02, 2008 1:43 am

maybe you want pack('ss', 5,0); ? or pack('SS'.. not super sure about creating C structures.
Last edited by frantik on Thu Oct 02, 2008 2:28 am, edited 1 time in total.
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Thu Oct 02, 2008 2:31 am

maybe it needs to be unsigned (SS or VV) ? I really don't know but i would try all of the short letters
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Thu Oct 02, 2008 2:59 am

ok well just using 0 for uCoord moves the cursor to 0,0 so the function is working. perhaps experiment with values and see what happens?

edit: values 0-79 move the cursor along the top line. now to find out what the y values are
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Thu Oct 02, 2008 3:09 am

this works for me

Code: Select all
...
$x = 2;
$y = 7;

nSetConsoleCursorPosition($y * 0x10000 + $x, nGetStdHandleOut());
nWriteConsole("Test");


i think the problem is pack returns a string and the function expects a numeric value. the dll example using pack calls for the value to be a "lp" which i think is long pointer, and Coord is a "dwCursorPosition" and dw is DWORD. i'm still not sure though..

you could convert the bytes from pack into a number but the math above is much easier :D
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Fri Oct 03, 2008 10:14 am

i don't know about writing text in a rectangle, but here's a shorter version of your program. I really dislike having to define EVERY function of the api :(

Code: Select all
<?php

define('STD_OUTPUT_HANDLE', 0x100000000 - 11);

class WindowsLibrary
{
   protected $libraryPtr;
   
   public function __construct($libraryName)
   {  $this->libraryPtr = wb_load_library($libraryName);
   }
         
   public function __call($functionName, $params)
   { 
      if ($functionPtr = wb_get_function_address($functionName, $this->libraryPtr))
      {  return wb_call_function($functionPtr, $params);
      }
      else
      {  return false;
      }
   }
}

// init KERNEL32 for resource functions
$KERNEL32 = new WindowsLibrary("KERNEL32");


$x = 2;
$y = 7;
$handle = $KERNEL32->GetStdHandle(STD_OUTPUT_HANDLE);
$KERNEL32->SetConsoleCursorPosition($handle , $y * 0x10000 + $x);
$KERNEL32->WriteConsole($handle, wb_get_address($str = "test"), strlen($str), NULL, NULL);

echo '!'

?>


this is also kinda cool:

Code: Select all
$KERNEL32->SetConsoleTextAttribute($handle, $color);


where color is a value between 0x00 and 0xff based on this table
#define FOREGROUND_BLUE 0x0001 /* text color contains blue. */
#define FOREGROUND_GREEN 0x0002 /* text color contains green. */
#define FOREGROUND_RED 0x0004 /* text color contains red. */
#define FOREGROUND_INTENSITY 0x0008 /* text color is intensified. */
#define BACKGROUND_BLUE 0x0010 /* background color contains blue. */
#define BACKGROUND_GREEN 0x0020 /* background color contains green. */
#define BACKGROUND_RED 0x0040 /* background color contains red. */
#define BACKGROUND_INTENSITY 0x0080 /* background color is intensified. */


being able to set the console cursor location and the color is pretty cool... for 1993 maybe :P lol still fun though
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Wed Oct 08, 2008 9:54 am

Before calling EnumDisplayDevices, you must initialize the cb member of DISPLAY_DEVICE to the size, in bytes, of DISPLAY_DEVICE.

http://msdn.microsoft.com/en-us/library/ms533226(VS.85).aspx


typedef struct _DISPLAY_DEVICE {
DWORD cb;
TCHAR DeviceName[32];
TCHAR DeviceString[128];
DWORD StateFlags;
TCHAR DeviceID[128];
TCHAR DeviceKey[128];
} DISPLAY_DEVICE, *PDISPLAY_DEVICE;

cb
Size, in bytes, of the DISPLAY_DEVICE structure. This must be initialized prior to calling EnumDisplayDevices.

http://msdn.microsoft.com/en-us/library/ms533254(VS.85).aspx


i think the size is 420 bytes.. so struct would be an string 420 bytes long starting with 01a0 i think.. or maybe a001?

edit:
ok i got it working with this...

$str32 = str_repeat(" ", 32);
$str128 = str_repeat(" ", 128);
$tBuffer = pack("La32a128La128a128", 424, $str32, $str128, 0, $str128, $str128);

i didnt unpack it sucessfully yet but if you echo the contents of tBuffer after the call you can see the function call worked
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Wed Oct 15, 2008 5:38 am

hmm.. i dunno why that is, but it's occurring on my system too


edit: i noticed it's occurring only when wb_call_function is used with parameters. I looked at the C code for wb_call_function and I think perhaps it doesn't clean up after it allocates space for the array of parameters. So might be a bug that rubem would have to fix :(

on line 307 of phpwb_lowlevel.c it says

Code: Select all
   // Cannot cleanup here
   //efree(param);
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby protheos » Wed Oct 15, 2008 9:51 am

Hrm... Actually - when uncommenting that line (and recompiling) - everything seems to be working fine (+ no memleak) -- I'm not really sure about the reason why it was commented out :/
Everything is possible... was possible... um... will be possible...
User avatar
protheos
 
Posts: 96
Joined: Wed Apr 18, 2007 8:07 am
Location: Estonia / Tallinn

Postby rubem » Wed Oct 15, 2008 2:10 pm

frantik wrote:...So might be a bug that rubem would have to fix :(


I'd love if someone would collect all those corrections and issue a new build with new fixes. That's the point of being open source! Anyone?
Rubem Pechansky
The WinBinder Guy
User avatar
rubem
Site Admin
 
Posts: 731
Joined: Fri Jan 07, 2005 2:15 pm
Location: Porto Alegre, Brazil

Postby frantik » Wed Oct 15, 2008 5:55 pm

i just meant u would know why that one line was commented out.. but it seems perhaps it works fine without it commented :)
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby frantik » Mon Oct 20, 2008 8:09 am

i made dlls with the updated code.. use at your own risk as I'm not 100% sure i did everything correctly... but no memory leaks calling windows functions :D

http://www.swiftlytilting.com/download. ... binder.zip
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby krakjoe » Mon Oct 20, 2008 3:10 pm

Maybe frantik ( and me and me ) could get write access to SVN/CVS, WB could be like ffmpeg and not release final versions until it's good and ready.

It's great that frantik took the time to rebuild, but it's a bit silly that the sources aren't published, you don't want for there to be a billion dll's floating around the internet with the same build numbers, you'll get posts like "if the dll you're using is 1023349kb then do this, if it's 123287443kb then do that" ...

Or do I misunderstand, are these changes in the source already ??
krakjoe
 
Posts: 98
Joined: Wed Oct 25, 2006 7:11 pm
Location: UK

Postby frantik » Mon Oct 20, 2008 4:47 pm

the only change is on line 308 of phpwb_lowlevel.c, it's uncommented

i gave the new snapshot version name 0.46.190 instead of 189.. but the 0.46.0 one i didn't give a new name. perhaps 0.46.fr or something? lol

edit: i included the changed file in the zip, and also renamed the 46.0 dll, but the changes are reflected in the code (ie winbinder will still say version 46.0)
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Postby nop » Fri Jan 09, 2009 10:45 am

frantik wrote:i made dlls with the updated code.. use at your own risk as I'm not 100% sure i did everything correctly... but no memory leaks calling windows functions :D

http://www.swiftlytilting.com/download. ... binder.zip
Neither the first nor the second version in this archive works for me: "This application has failed to start because the application configuration is incorrect.". Seems like you forget to set the correct runtime library (which could be the reason for the file size of your versions)... :?
nop
 
Posts: 2
Joined: Fri Jan 09, 2009 10:31 am
Location: Germany

Postby frantik » Sat Jan 10, 2009 8:57 pm

the file size has to do with optimizations i set when compiling the files

and i really had no idea what i was doing with regards to compiling the DLLs.. sorry they dont work for you
frantik
 
Posts: 595
Joined: Tue Mar 22, 2005 7:17 am
Location: California


Return to Beginners' Place

cron