Getting double return value from DLL

Just starting out? Need help? Post your questions and find answers here.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Getting double return value from DLL

Post 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,
El_Choni
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Getting double return value from DLL

Post 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
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Getting double return value from DLL

Post by Demivec »

If you use PureBasic versions 5.10 + you can't use this syntax for pointers anymore:

Code: Select all

*capture.l
Either leave it without a type (i.e '*capture') or give it a structure (i.e. *capture.Integer).
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Re: Getting double return value from DLL

Post 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,
El_Choni
Helle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Apr 12, 2006 7:59 pm
Location: Germany
Contact:

Re: Getting double return value from DLL

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Getting double return value from DLL

Post 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.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Re: Getting double return value from DLL

Post 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,
El_Choni
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Getting double return value from DLL

Post 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
Helle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Apr 12, 2006 7:59 pm
Location: Germany
Contact:

Re: Getting double return value from DLL

Post 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.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Re: Getting double return value from DLL

Post by El_Choni »

Interesting read, thank you!
El_Choni
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Getting double return value from DLL

Post 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 :lol: should be a Trademark :mrgreen:
Post Reply