D
dafritz
Ive been writing a program that uses a windows dll to write spss files.
This is my first experience using dlls in ruby and am fairly
inexperienced with the ruby language as well. The problem I am having
is recieving pointer values that should be returned through a
referenced object.
For example...
create_file = Win32API.new("spssio32.dll", "spssOpenWrite", ['P', 'P'],
'I')
takes a file name and a pointer which acts as the file handle. once the
file is created the handle is stored in the file handle and returned by
reference. My call to the function looks like this:
@file_handle=""
puts create_file.Call("testFile.sav", @file_handle)
The return value of the function is simply 0 for success or one of
several other various return error codes. I am recieving a return value
of 0 and the file is being created which is good, however, when i use
@file_handle for future calls to other functions to actually write to
the file, i get a return value of "Invalid File Handle." when i display
@file_handle i get 'nil'.
I was hoping someone here could help explain why the file pointer is
not being stored in @file_handle. Do i need to use pack and unpack to
extract this data? for reference here is a quick description of the
spssOpenWrite and a small c++ example.
___________________________________________________________-
int spssOpenWrite (const char *filename, int *handle)
Description
This function opens a file in preparation for creating a new SPSS data
file and returns
a handle that should be used for subsequent operations on the file.
Parameter Description
filename Name of the data file
handle Pointer to handle to be returned
Returns
One of the following codes. Success is indicated by zero (SPSS_OK),
errors by positive
values, and warnings, if any, by negative values.
Error Code Description
SPSS_OK No error
SPSS_FITAB_FULL File table full (too many open SPSS data
files)
SPSS_FILE_OERROR Error opening file
SPSS_NO_MEMORY Insufficient memory
Example
#include "spssdio.h"
void func()
{
int fH; /* file handle */
int error; /* error code */
...
error = spssOpenWrite("dat.sav", &fH);
if (error == 0)
{
/* fH is a valid handle; process and */
...
/* close file */
error = spssCloseWrite(fH);
...
}
else
{
/* Handle error*/
...
}
}
This is my first experience using dlls in ruby and am fairly
inexperienced with the ruby language as well. The problem I am having
is recieving pointer values that should be returned through a
referenced object.
For example...
create_file = Win32API.new("spssio32.dll", "spssOpenWrite", ['P', 'P'],
'I')
takes a file name and a pointer which acts as the file handle. once the
file is created the handle is stored in the file handle and returned by
reference. My call to the function looks like this:
@file_handle=""
puts create_file.Call("testFile.sav", @file_handle)
The return value of the function is simply 0 for success or one of
several other various return error codes. I am recieving a return value
of 0 and the file is being created which is good, however, when i use
@file_handle for future calls to other functions to actually write to
the file, i get a return value of "Invalid File Handle." when i display
@file_handle i get 'nil'.
I was hoping someone here could help explain why the file pointer is
not being stored in @file_handle. Do i need to use pack and unpack to
extract this data? for reference here is a quick description of the
spssOpenWrite and a small c++ example.
___________________________________________________________-
int spssOpenWrite (const char *filename, int *handle)
Description
This function opens a file in preparation for creating a new SPSS data
file and returns
a handle that should be used for subsequent operations on the file.
Parameter Description
filename Name of the data file
handle Pointer to handle to be returned
Returns
One of the following codes. Success is indicated by zero (SPSS_OK),
errors by positive
values, and warnings, if any, by negative values.
Error Code Description
SPSS_OK No error
SPSS_FITAB_FULL File table full (too many open SPSS data
files)
SPSS_FILE_OERROR Error opening file
SPSS_NO_MEMORY Insufficient memory
Example
#include "spssdio.h"
void func()
{
int fH; /* file handle */
int error; /* error code */
...
error = spssOpenWrite("dat.sav", &fH);
if (error == 0)
{
/* fH is a valid handle; process and */
...
/* close file */
error = spssCloseWrite(fH);
...
}
else
{
/* Handle error*/
...
}
}