User Control Panel
Advertisements

HELP US, HELP YOU!

Inline::CPP

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Ideas
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Feb 09, 2005 12:59 pm    Post subject: Reply with quote

During my 0-hour class at school, I opened Windows Media Player and repeatedly hit the eject-cd shortcut (CTRL+E), and so every 10 seconds or so the CD drive would open and then close... and so I was wondering how I could make it do that in Perl.

The only search result on Google that had what I was looking for had code like this:

Code:
#!/usr/bin/perl -w<br />use warnings;<br />use Inline C;<br />use strict;<br /><br />my $cd = '/dev/cdrom';<br /><br />cdlock($cd,0); #unlocks cdrom <br />cdeject($cd);  #ejects cdrom <br />cdclose($cd);  #closes cdrom <br />cdlock($cd,1); #locks cdrom  <br /><br />exit;<br /><br />__END__ <br />__C__ <br />#include <stdio.h> <br />#include <sys/ioctl.h> <br />#include <linux/cdrom.h> <br />#include <fcntl.h> <br />#include <unistd.h> <br />#include <stdlib.h> <br /> <br />/* In all functions 'device' means name of CD-ROM device, <br />* for example /dev/cdrom <br />*/ <br /> <br />/* Close CD-ROM tray */ <br />int cdclose(char *device) <br />{ <br />int fd = open(device, O_RDONLY|O_NONBLOCK); <br />if (fd == -1) <br />return -1; <br />if (ioctl(fd, CDROMCLOSETRAY) == -1) <br />return -1; <br />close(fd); <br />return 0; <br />} <br /> <br />/* Eject CD-ROM tray */ <br />int cdeject(char *device) <br />{ <br />int fd = open(device, O_RDONLY|O_NONBLOCK); <br />if (fd == -1) <br />return -1; <br />if (ioctl(fd, CDROMEJECT) == -1) <br />return -1; <br />close(fd); <br />return 0; <br />} <br /><br />/* Lock (if lock==1) or unlock (if lock==0) CD-ROM tray */ <br />int cdlock(char *device, int lock) <br />{ <br />int fd; <br />fd = open(device, O_RDONLY|O_NONBLOCK); <br />if (fd == -1) <br />return -1; <br />if (ioctl(fd, CDROM_LOCKDOOR, lock) == -1) <br />return -1; <br />close(fd); <br />return 0; <br />}


Another search result took me to a CPAN module page... and since I was at CPAN, I decided to do a search on this "Inline C" module, and found Inline::CPP.

The synopsis code was this:

Code:
   use Inline CPP;<br /><br />   print "9 + 16 = ", add(9, 16), "\n";<br />   print "9 - 16 = ", subtract(9, 16), "\n";<br /><br />   __END__<br />   __CPP__<br /><br />   int add(int x, int *lazy*) { <br />      return x + *lazy*;<br />   }<br /><br />   int subtract(int x, int *lazy*) {<br />      return x - *lazy*;<br />   }


Anyways, so the idea I got from this, is that you can use Perl as a wrapper for a C++ bot, and then you won't need to compile a C++ bot every time you want to go and test it (maybe save the compiling process for when the bot is complete and without errors?).

I'll test this when I get home (converting a C++ bot to Perl by using Inline::CPP). If it works, we can start programming C++ bots, in Perl! Very Happy

(there's also Inline::C and Inline::Java, by the way Razz ).

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
mattaustin
Sentinel
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Wed Feb 09, 2005 5:59 pm    Post subject: Reply with quote

Cool cer.....maybe you coul write that into your editor. So you can test script from with in it.


In perl to open cdrom WIN23:

Code:
<br />use Win32::OLE;<br /><br />my $CD = Win32::OLE->new('Shell.Application')->NameSpace(17)->ParseName('E:\\');<br />$CD->InvokeVerb('E&ject');<br />

_________________
[ matt ]
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Fri Apr 08, 2005 2:30 pm    Post subject: Reply with quote

while(1) {

use Win32::OLE;

my $CD = Win32::OLE->new('Shell.Application')->NameSpace(17)->ParseName('E:\\');
$CD->InvokeVerb('E&ject');

}
Back to top
mattaustin
Sentinel
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Fri Apr 08, 2005 5:30 pm    Post subject: Reply with quote

use Win32::OLE;

while(1) {
my $CD = Win32::OLE->new('Shell.Application')->NameSpace(17)->ParseName('E:\\');
$CD->InvokeVerb('E&ject');
}



bad to do a use in a loop

_________________
[ matt ]
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Fri Apr 08, 2005 8:24 pm    Post subject: Reply with quote

Quote:
I'll test this when I get home (converting a C++ bot to Perl by using Inline::CPP). If it works, we can start programming C++ bots, in Perl! biggrin.gif

Err, really, Cer? To me that would still be C++, otherwise C++ just got a magic makeover and was instantly transformed into Perl.

Plus, a good developer environment (VS, Borland, whatever floats your boat) is so much better at compiling C than Perl, I reckon. Not to mention I dont think Perl's Inline CPP will benefit speed.

Why use Perl if you can already compile it? Just for "testing purposes"? Sure it's cool, but I dont see the benifit of using it for BOTs, at all.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Ideas All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group