S
sajohn
I'm fairly new to c programming and am not very clear on pointers and
handles. Currently, I'm writting a wrapper script and I need to
interface with another application. I have decided that the wrapper
script could use some data structures and have defined a few. The
problem is that the application has defined some pointers that I could
use for my structures that are defined as unsigned long. I thought I
could write some code as follows
unsigned long HANDLE ;
unsigned long *PHANDLE ;
typedef struct
{
int i ;
float f ;
} Numbers ;
HANDLE hTest1 ;
PHANDLE *phTest2;
Numbers Num ;
hTest2 = (PHANDLE )malloc( HANDLE * ) ;
hTest1 = ( HANDLE )malloc( sizeof( Num ) ) ;
hTest2->i = 10 ;
hTest2->f = 127/13 ;
This code fails with an error indicating that I'm pointing to an hTest2
structure instead of a Num structure and cannot find i or f fields.
Then I thought I could something like this
hTest2->hTest1->i
to retrive the filed data but the results are the same.
I know a lot of this is my lack of understanding of pointers in general
but I was wondering if someone could tell me where I'm going wrong with
this code. Is it even possible to malloc a data structure in memory and
then re-cast its pointer type to an unsigned long?
TIA.
handles. Currently, I'm writting a wrapper script and I need to
interface with another application. I have decided that the wrapper
script could use some data structures and have defined a few. The
problem is that the application has defined some pointers that I could
use for my structures that are defined as unsigned long. I thought I
could write some code as follows
unsigned long HANDLE ;
unsigned long *PHANDLE ;
typedef struct
{
int i ;
float f ;
} Numbers ;
HANDLE hTest1 ;
PHANDLE *phTest2;
Numbers Num ;
hTest2 = (PHANDLE )malloc( HANDLE * ) ;
hTest1 = ( HANDLE )malloc( sizeof( Num ) ) ;
hTest2->i = 10 ;
hTest2->f = 127/13 ;
This code fails with an error indicating that I'm pointing to an hTest2
structure instead of a Num structure and cannot find i or f fields.
Then I thought I could something like this
hTest2->hTest1->i
to retrive the filed data but the results are the same.
I know a lot of this is my lack of understanding of pointers in general
but I was wondering if someone could tell me where I'm going wrong with
this code. Is it even possible to malloc a data structure in memory and
then re-cast its pointer type to an unsigned long?
TIA.