Jump to content

DllCall with inline function and struct parameter


Recommended Posts

I'm trying to test openCv and I want to call this func:

cvRectangle(img, cvPoint(100,100), cvPoint(200,200), cvScalar(255,0,0), 1);

defined as:

void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int lineType=8, int shift=0)

with

typedef struct CvPoint
{
    int x;
    int y;
}
CvPoint;
and the constructor
/* Constructor */
inline CvPoint cvPoint( int x, int y );
based on

CV_INLINE  CvPoint  cvPoint( int x, int y )
{
    CvPoint p;

    p.x = x;
    p.y = y;

    return p;
}

and CvScalar:

typedef struct CvScalar
{
    double val[4];
}
CvScalar;

CV_INLINE  CvScalar  cvScalar( double val0, double val1 CV_DEFAULT(0),
                               double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
{
    CvScalar scalar;
    scalar.val[0] = val0; scalar.val[1] = val1;
    scalar.val[2] = val2; scalar.val[3] = val3;
    return scalar;
}

I wrote the struct and pointer img and that works.

Then I do:

Global $cvCore_dll = DllOpen('opencv_core240d.dll')

Global $_cvPoint = 'int x;' & _
'int y;'
Global $_cvScalar=  'double val[4];'
Global $tPt1 = DllStructCreate($_cvPoint)
DllStructSetData($tPt1,1,100)
DllStructSetData($tPt1,2,100)

Global $tPt2 = DllStructCreate($_cvPoint)
DllStructSetData($tPt2,1,250)
DllStructSetData($tPt2,2,400)

Global $tCvColor = DllStructCreate($_cvScalar)
DllStructSetData($tCvColor,1,255,1) ;blue
DllStructSetData($tCvColor,1,0,2)
DllStructSetData($tCvColor,1,0,3)
DllStructSetData($tCvColor,1,0,4)

;~ lineType : 8 - (or omitted) 8-connected line , 4 - 4-connected line, CV_AA - antialiased line.
;~ Thickness of lines that make up the rectangle. Negative values, e.g., CV_FILLED, cause the function to draw a filled rectangle.

DllCall($cvCore_dll, 'none:cdecl','cvRectangle', 'ptr' , DllStructGetPtr($tIplImage) , 'struct' , $tPt1,'struct',$tPt2,'struct',$tCvColor,'int',1,'int',8,'int',0) ;
ConsoleWrite('Rectangle:'&@error&' ext:'&@extended &@CRLF)

it gives me @error=1

I tried also

DllCall($cvCore_dll, 'none:cdecl','cvPoint', 'int' , 100 , 'int' , 150) ;
ConsoleWrite('Point:'&@error&' ext:'&@extended &@CRLF)

@error=3,

so it should not be in the core.dll but it's present in the types_c.h

Edited by frank10
Link to post
Share on other sites

I used Dll Export Viewer and I saw that it exists the cvRectangle func:

Function Name    : cvRectangle
Function Name    : cvRectangleR

but instead it doesn't exist the 'cvPoint' name func.

Instead it's written in this way:

Function Name    : public: __thiscall cv::Point_<int>::Point_<int>(class cv::Point_<int> const &)
Function Name    : public: __thiscall cv::Point_<int>::Point_<int>(int,int)
Function Name    : public: __thiscall cv::Point_<int>::Point_<int>(struct CvPoint const &)
Function Name    : public: __thiscall cv::Point_<int>::Point_<int>(void)

Is there a way to call it in DllCall?

Edited by frank10
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...