Just starting out? Need help? Post your questions and find answers here.
eddy
Addict
Posts: 1479 Joined: Mon May 26, 2003 3:07 pm
Location: Nantes
Post
by eddy » Fri Feb 01, 2008 1:04 am
Hi,
How can I convert this ?
I know PB procedures can return structure pointer.
But C functions can return a structure without any pointer.
Code: Select all
struct MyResultStruct MyProcedure(void) {.....;}
win10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
inc.
Enthusiast
Posts: 406 Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER
Post
by inc. » Fri Feb 01, 2008 8:33 am
Imho not possible.
Whats the size of the struct? If it wont exceed 64bit/8bytes you can wrap it into a quad variable.
Check out OOP support for PB here!
tinman
PureBasic Expert
Posts: 1102 Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:
Post
by tinman » Fri Feb 01, 2008 11:45 am
eddy wrote: Hi,
How can I convert this ?
I know PB procedures can return structure pointer.
But C functions can return a structure without any pointer.
Code: Select all
struct MyResultStruct MyProcedure(void) {.....;}
I showed Mistrel some code recently that showed how C does this. It takes a pointer to the structure to return as a hidden parameter to the procedure. In PB you would need to do this manually:
Code: Select all
Procedure MyProcedure(*return_structure.MyStructure)
EndProcedure
Define.MyStructure my_value
MyProcedure(@my_value)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
eddy
Addict
Posts: 1479 Joined: Mon May 26, 2003 3:07 pm
Location: Nantes
Post
by eddy » Fri Feb 01, 2008 1:42 pm
I see ... Thanks.
I'll test this code.
win10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
traumatic
PureBasic Expert
Posts: 1661 Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:
Post
by traumatic » Fri Feb 01, 2008 2:27 pm
What about using Static?
Good programmers don't comment their code. It was hard to write, should be hard to read.
eddy
Addict
Posts: 1479 Joined: Mon May 26, 2003 3:07 pm
Location: Nantes
Post
by eddy » Sun Feb 10, 2008 3:04 am
It does not work like in your example... I tested DLL and Staticlib
versions.
For information, I found how to convert this kind of function by using "ImportC"
But it's bad... the returned type can be bigger than 8 bytes (.q)
Code: Select all
Structure cpVect
x.f
y.f
EndStructure
ImportC "ChipmunkLib.a.lib"
cpvforangle.q(a.f)
EndImport
v_cpVect.q = cpvforangle(#PI/4.0)
v.cpVect
v\x= PeekF(@v_cpVect+OffsetOf(cpVect\x))
v\y= PeekF(@v_cpVect+OffsetOf(cpVect\y))
Debug v\x
Debug v\y
win10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
eddy
Addict
Posts: 1479 Joined: Mon May 26, 2003 3:07 pm
Location: Nantes
Post
by eddy » Sun Feb 10, 2008 4:22 pm
it's better with DLL : there's no limitation
Code: Select all
Structure cpVect
x.f
y.f
EndStructure
If OpenLibrary(1,"chipmunk-4.0.2.dll")
func = GetFunction(1,"cpvforangle")
v_cpVect=CallFunctionFast(func,#PI/4.0)
v.cpVect
v\x= PeekF(@v_cpVect+OffsetOf(cpVect\x))
v\y= PeekF(@v_cpVect+OffsetOf(cpVect\y))
Debug v\x
Debug v\y
EndIf
win10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool