Getting memory address out of c into bmax
BlitzMax Forums/BlitzMax Programming/Getting memory address out of c into bmax
| ||
Hi all. How would I get go about getting the memory address of, say a texture, in a c program and use the same memory address in my bmax program? Or to put it another way I want to be able to know the address of a texture in both my bmax proggy and my c proggy, and be able to pass the address from c into bmax then back into c. [EDIT]Blimey that isn't very clear is it??? Do you understand what I mean? Cheers |
| ||
I see what you mean. I'm working on a MD2Loader c Module but dont know how to access the memory address of my C class from BMAX without having a billion params in my extends function ... regards |
| ||
varptr is the same as a pointer in c ( of the specific type of the var following it ) so to call a c function you use varptr and vice versa |
| ||
Like this :- In BMaxgl.c int texture=90; //test function long ptrGetTexture() { return &texture; } In my gl.mod folder use:- Import "BMaxGL.c" Extern Function ptrGetTexture:Int() EndExtern Function glGetTexturePTR:Int() Return ptrGetTexture() End Function Then I create program file to get the address of the texture I use :- Import nrg.gl Print glGetTexturePTR() This seems to give me the address. Is this what you mean?? Thanks |
| ||
your function does not return an int but a int ptr ( or I think more a byte ptr than int ptr ) if you try to access to it as int it should give you an error. |
| ||
@Dreamora It is infact returning the correct address of the 'texture variable' as a integer value. Thanks, coz you made me remember there are variable pointers built into blitz :) @mouss38 Are you trying to access structures from a c program but within bmax? If so, then I just solved that problem ( well, one way - from c into bmax at the mo ) :p c program: typedef struct { int x; int y; } test; test t; //test function long GetPointer() { t.x=10; t.y=20; return &t; } .mod program: Extern Function GetPointer:Int Ptr() EndExtern Function GetMemPtr:Int Ptr() Return GetPointer() End Function .bmax program: Local test:Int Ptr test = getmemptr() Print test[0] test:+1 Print test[0] 'or you could use:- test = getmemptr() Print test[0] Print test[1] Does this help? [EDITED} Strange..... for some reason a c++ version of the program gives an 'undefined reference to `GetPointer' ' error. [EDITED ADGAIN] OK, So I've learned that the calling conventoin in c++ needs the 'extern 'c' ' command around your function prototypes. Learning more and more everyday..... |