A snippet of the code around the Get and Make parts:
....
SQLHANDLE hDb;
VALUE retVal;
handle hCon;
VALUE conRet;
sConnect *sC;
conRet = Data_Make_Struct(cDB2Conn, sConnect, 0, free, sC);
sC->connection = hDb;
return conRet;
and the later part where it's used:
handle *hCon;
Data_Get_Struct( conHandle, handle, hCon );
(What type is conHandle? It should be a VALUE holding a Class)
OK, so you the 'c-type' you gave to Data_Make_Struct was sConnect, but
you're asking for something with a type of handle back, wouldn't you want:
sConnect *hCon;
Data_Get_Struct( conHandle, sConnect, hCon);
instead?
This is where it fails with "incorrect class - Data expected"
Well, I didn't use Data_Make_Struct, but here's an example from my code
using Data_Wrap_Struct, maybe it'll help:
/*begin point.c code*/
typedef struct {
double x;
double y;
double z;
} ACO_3DPoint_Struct;
//allocator
static VALUE aco_point_alloc(VALUE klass) {
VALUE object;
ACO_3DPoint_Struct* point = (ACO_3DPoint_Struct*)malloc(sizeof(
ACO_3DPoint_Struct));
object = Data_Wrap_Struct(klass,0,aco_point_free,point);
return object;
}
//initialize
static VALUE aco_point_init(VALUE self, VALUE x, VALUE y, VALUE z){
ACO_3DPoint_Struct* _self ;
//double x, y;
Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
_self->x = NUM2DBL(x);
_self->y = NUM2DBL(y);
_self->z = NUM2DBL(z);
return self;
}
static VALUE aco_point_getx(VALUE self){
ACO_3DPoint_Struct *_self;
Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
return rb_float_new(_self->x);
}
static VALUE aco_point_setx(VALUE self, VALUE x){
ACO_3DPoint_Struct* _self;
Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
_self->x = NUM2DBL(x);
}
//skip a lot of stuff...
VALUE cACOMod;
VALUE cACOPoint3D;
void Init_aco_point3d() {
printf("ACO_Ext initializing...\n");
cACOMod = rb_define_module("ACO");
cACOPoint3D = rb_define_class_under(cACOMod,"Point3D",rb_cObject);
//cACOPoint3D = rb_define_class_under(cACOMod,"Point3D",rb_cObject);
cACOGraph = rb_define_class_under(cACOMod,"Graph",rb_cObject);
rb_define_alloc_func(cACOPoint3D, aco_point_alloc);
rb_define_method(cACOPoint3D,"initialize",aco_point_init,3);
//skip a lot of operators
}
/*end point.c */
Phil