I am having a hard time with this one.
So I am using the old Win32API in ruby and I have a DLL function GetStruct that returns a pointer to a structure, my ruby looks a bit like this;
The structure in C++ looks like this:
I call this code:
a b and c are all nil, but the code runs perfectly fine?
I tried returning the structure itself instead of a pointer to it, but the whole thing crashes.
I am testing this in RPG Maker VX.
The full C++ source of my DLL function:
What am I misunderstanding here and what do I do????
EDIT: I kind of understand now that I need to provide a buffer via ruby to store the struct data, can anyone help me out here?
EDIT2: So I have it being able to return integers from the structure perfectly fine, but I have trouble with that C character pointer (The text "Winner") how do I go about doing this? With the Win32API I can usually use the pointer "P" return type and my c strings will cast into ruby strings nicely, but I can't figure it out here
So I am using the old Win32API in ruby and I have a DLL function GetStruct that returns a pointer to a structure, my ruby looks a bit like this;
Ruby:
module XNE
@getStruct = Win32API.new( 'XNE100a', 'XNE_GetStruct', 'V', 'P' )
def self.GetStruct
return @getStruct.call
end
end
The structure in C++ looks like this:
C++:
typedef int integer_t; // I
typedef long long_t; // L
typedef void void_t; // V
typedef void * pointer_t; // P
typedef struct struct_s {
integer_t integer;
long_t longInteger;
pointer_t string;
} struct_t;
I call this code:
Ruby:
test = XNE::GetStruct()
a, b, c = test.unpack('ILP')
print a, b, c
a b and c are all nil, but the code runs perfectly fine?
I tried returning the structure itself instead of a pointer to it, but the whole thing crashes.
I am testing this in RPG Maker VX.
The full C++ source of my DLL function:
C++:
typedef int integer_t; // I
typedef long long_t; // L
typedef void void_t; // V
typedef void * pointer_t; // P
typedef struct struct_s {
integer_t integer;
long_t longInteger;
pointer_t string;
} struct_t;
__declspec( dllexport ) pointer_t XNE_GetStruct( void_t );
pointer_t XNE_GetStruct( void_t ) {
struct_t * const result = <span style="color: #0000dd;">new struct_t;
result->integer = <span style="color: #0000dd;">54;
result->longInteger = <span style="color: #0000dd;">108;
result->string = <span style="color: #666666;">"Winner";
return result;
}
What am I misunderstanding here and what do I do????
EDIT: I kind of understand now that I need to provide a buffer via ruby to store the struct data, can anyone help me out here?
EDIT2: So I have it being able to return integers from the structure perfectly fine, but I have trouble with that C character pointer (The text "Winner") how do I go about doing this? With the Win32API I can usually use the pointer "P" return type and my c strings will cast into ruby strings nicely, but I can't figure it out here