Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Open a windows device file handle in ruby?

Reply
Thread Tools

Open a windows device file handle in ruby?

 
 
Qaz Qaz
Guest
Posts: n/a
 
      10-07-2010
Hello, I have windows device driver which creates a symbolic link for
the path '\\.\MyDevice'. In C I can then use CreateFile() to open this
device, e.g.

---[c
snippet]------------------------------------------------------------------
handle = CreateFile( "\\\\.\\MyDevice", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );

WriteFile( handle, data, len, &written, NULL );

CloseHandle( handle );
---[c
snippet]------------------------------------------------------------------

However in Ruby, I should be able to simple use something like:

---[ruby
snippet]---------------------------------------------------------------
handle = open( "\\\\.\\MyDevice", File::RDWR )
handle.syswrite( data )
handle.close
---[ruby
snippet]---------------------------------------------------------------

but it does not work and segfaults the ruby interpreter during the open!

Can anybody please help as to what I am doing wrong. How do you open a
file handle to a device in windows?

Thanks!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Charles Calvert
Guest
Posts: n/a
 
      10-20-2010
On Thu, 7 Oct 2010 11:43:29 -0500, Qaz Qaz <(E-Mail Removed)>
wrote in <(E-Mail Removed)>:

>Hello, I have windows device driver which creates a symbolic link for
>the path '\\.\MyDevice'. In C I can then use CreateFile() to open this
>device, e.g.
>
>---[c
>snippet]------------------------------------------------------------------
>handle = CreateFile( "\\\\.\\MyDevice", GENERIC_READ|GENERIC_WRITE,
>FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
>
>WriteFile( handle, data, len, &written, NULL );
>
>CloseHandle( handle );
>---[c
>snippet]------------------------------------------------------------------
>
>However in Ruby, I should be able to simple use something like:
>
>---[ruby
>snippet]---------------------------------------------------------------
>handle = open( "\\\\.\\MyDevice", File::RDWR )
>handle.syswrite( data )
>handle.close
>---[ruby
>snippet]---------------------------------------------------------------
>
>but it does not work and segfaults the ruby interpreter during the open!


Your assumption that you should be able to use standard Ruby IO
functions seems suspicious to me. What happens if you write C code
that attempts to open the file using fopen() and write to it with
fputs()? If that fails, then you have your answer.

Instead, you could call the Win32API functions CreateFile() and
WriteFile() from Ruby using either the Ruby Win32API library or
dl/win32 (see
http://stdlib.rubyonrails.org/libdoc...I.html#M000496).

--
Charles Calvert
Moderator - alt.computer.consultants.moderated
Submission Address: http://www.velocityreviews.com/forums/(E-Mail Removed)
Contact Address: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Package to handle table text render (handle space or tab betweenthe columns) ? =?ISO-8859-1?Q?KLEIN_St=E9phane?= Python 3 10-06-2006 08:46 AM
Possible to handle web requests without an ASPX page? i.e. have DLL handle request. jdlwright@shaw.ca ASP .Net 2 05-31-2005 05:42 PM
How to install Smart Device app on mobile device from Windows app Matt ASP .Net Mobile 0 12-02-2004 11:53 AM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM



Advertisments