Page 1 of 1
Getting double return value from DLL
Posted: Thu Jan 10, 2013 7:07 pm
by El_Choni
Hi all,
I'm trying to figure out how to get a "double" value from a C DLL but I'm unable to do so. The function is
cvGetCaptureProperty from opencv_highgui243d.dll (in short,
OpenCV).
Code: Select all
Enumeration
#CV_CAP_PROP_POS_MSEC
#CV_CAP_PROP_POS_FRAMES
#CV_CAP_PROP_POS_AVI_RATIO
#CV_CAP_PROP_FRAME_WIDTH
#CV_CAP_PROP_FRAME_HEIGHT
#CV_CAP_PROP_FPS
#CV_CAP_PROP_FOURCC
#CV_CAP_PROP_FRAME_COUNT
EndEnumeration
;
PrototypeC.l cvCreateFileCapture(filename$)
PrototypeC.d cvGetCaptureProperty(integer.l, flags.l)
;
If OpenLibrary(0, "opencv_highgui243d.dll")
If OpenLibrary(1, "opencv_ffmpeg243_64.dll")
If OpenLibrary(2, "opencv_core243d.dll")
CreateFileCapture.cvCreateFileCapture = GetFunction(0, "cvCreateFileCapture")
GetCaptureProperty.cvGetCaptureProperty = GetFunction(0, "cvGetCaptureProperty")
filename$ = OpenFileRequester("Choose a video file", "", "All Files|*.*", 0)
If filename$
*capture.l = CreateFileCapture(filename$)
If *capture
fps.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FPS)
fc.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_COUNT)
w.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
h.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT)
Debug StrD(w)+" "+StrD(h)
EndIf
EndIf
EndIf
EndIf
EndIf
End
Do you have any clue on how to achieve this?
Thank you very much in advance, and regards,
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 3:40 am
by idle
Sorry I can't test it at the moment but If you're compiling it for 64 bit
the prototype for CreateFileCapture would be wrong, it would need to be an Integer
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 9:36 am
by Demivec
If you use PureBasic versions 5.10 + you can't use this syntax for pointers anymore:
Either leave it without a type (i.e '*capture') or give it a structure (i.e. *capture.Integer).
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 10:07 am
by El_Choni
Thank you very much. I've wiped out the * as per new syntax constraints, and switched the return variable type to i (I'm compiling in x64). Still won't work
Code: Select all
Enumeration
#CV_CAP_PROP_POS_MSEC
#CV_CAP_PROP_POS_FRAMES
#CV_CAP_PROP_POS_AVI_RATIO
#CV_CAP_PROP_FRAME_WIDTH
#CV_CAP_PROP_FRAME_HEIGHT
#CV_CAP_PROP_FPS
#CV_CAP_PROP_FOURCC
#CV_CAP_PROP_FRAME_COUNT
EndEnumeration
;
PrototypeC.l cvCreateFileCapture(filename$)
PrototypeC.i cvGetCaptureProperty(integer.l, flags.l)
;
OpenCVDir$ = "C:\Program Files (x86)\opencv\build\x64\vc10\bin\"
If OpenLibrary(0, OpenCVDir$+"opencv_highgui243d.dll")
If OpenLibrary(1, OpenCVDir$+"opencv_ffmpeg243_64.dll")
If OpenLibrary(2, OpenCVDir$+"opencv_core243d.dll")
CreateFileCapture.cvCreateFileCapture = GetFunction(0, "cvCreateFileCapture")
GetCaptureProperty.cvGetCaptureProperty = GetFunction(0, "cvGetCaptureProperty")
filename$ = OpenFileRequester("Choose a video file", "", "All Files|*.*", 0)
If filename$
capture.l = CreateFileCapture(filename$)
If capture
fps.i = GetCaptureProperty(capture, #CV_CAP_PROP_FPS)
fc.i = GetCaptureProperty(capture, #CV_CAP_PROP_FRAME_COUNT)
w.i = GetCaptureProperty(capture, #CV_CAP_PROP_FRAME_WIDTH)
h.i = GetCaptureProperty(capture, #CV_CAP_PROP_FRAME_HEIGHT)
Debug Str(w)+" "+Str(h)
EndIf
EndIf
EndIf
EndIf
EndIf
End
Any further clues?
Thank you again and regards,
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 10:58 am
by Helle
If the return-value is double and x64, use this e.g.:
Code: Select all
GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
w.d
!movsd [v_w],xmm0
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 11:07 am
by Demivec
Code: Select all
double cvGetCaptureProperty( CvCapture* capture, int property_id );
After looking at the return value for the function it seems as if your first attempt (using a prototype and a double return value) should have worked.
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 12:02 pm
by El_Choni
Helle wrote:If the return-value is double and x64, use this e.g.:
Code: Select all
GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
w.d
!movsd [v_w],xmm0
This worked, thank you! (is this a PB bug, not being able to get this return value normally?)
Regards,
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 12:11 pm
by PMV
Pointers have the same dimension as integers, so only! use
integers for them as return. I just don't know the declaration
of "int" so i have no clue if it is only 32-Bit or 64-Bit.
Maybe parameter "property_id" of cvGetCaptureProperty
could be not a long, but something else.
Code: Select all
Enumeration
#CV_CAP_PROP_POS_MSEC
#CV_CAP_PROP_POS_FRAMES
#CV_CAP_PROP_POS_AVI_RATIO
#CV_CAP_PROP_FRAME_WIDTH
#CV_CAP_PROP_FRAME_HEIGHT
#CV_CAP_PROP_FPS
#CV_CAP_PROP_FOURCC
#CV_CAP_PROP_FRAME_COUNT
EndEnumeration
;CvCapture* cvCreateFileCapture( const char* filename );
PrototypeC.i cvCreateFileCapture(filename$)
;double cvGetCaptureProperty( CvCapture* capture, int property_id );
PrototypeC.d cvGetCaptureProperty(*capture, property_id.l)
;
If OpenLibrary(0, "opencv_highgui243d.dll")
If OpenLibrary(1, "opencv_ffmpeg243_64.dll")
If OpenLibrary(2, "opencv_core243d.dll")
CreateFileCapture.cvCreateFileCapture = GetFunction(0, "cvCreateFileCapture")
GetCaptureProperty.cvGetCaptureProperty = GetFunction(0, "cvGetCaptureProperty")
filename$ = OpenFileRequester("Choose a video file", "", "All Files|*.*", 0)
If filename$
*capture = CreateFileCapture(filename$)
If *capture
fps.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FPS)
fc.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_COUNT)
w.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
h.d = GetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT)
Debug StrD(w)+" "+StrD(h)
EndIf
EndIf
EndIf
EndIf
EndIf
End
MFG PMV
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 1:33 pm
by Helle
@El_Choni: See
http://en.wikipedia.org/wiki/X86_calling_conventions. "Microsoft x64 calling convention: ...Floating point return values are returned in XMM0...".
PB (x64) uses ST(0) from the FPU (like in PB (x86)). I hope, F&F will change this in the future.
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 3:09 pm
by El_Choni
Interesting read, thank you!
Re: Getting double return value from DLL
Posted: Fri Jan 11, 2013 3:26 pm
by PMV
Helle wrote:@El_Choni: See
http://en.wikipedia.org/wiki/X86_calling_conventions. "Microsoft x64 calling convention: ...Floating point return values are returned in XMM0...".
PB (x64) uses ST(0) from the FPU (like in PB (x86)). I hope, F&F will change this in the future.
Shouldn't be that posted in Bug-Section?
PS: F&F

should be a Trademark
