returning and passing CArrays

This is a discussion on returning and passing CArrays within the Windows Programming forums, part of the Platform Specific Boards category; CArray<CPoint , CPoint > arrayTemp; .. ... .... rgn.CreatePolygonRgn(arrayTemp, count, ALTERNATE); when i call CreatePolygonRgn with arrayTemp i get the ...

  1. #1
    swordfish
    Guest

    returning and passing CArrays

    CArray<CPoint , CPoint > arrayTemp;
    ..
    ...
    ....
    rgn.CreatePolygonRgn(arrayTemp, count, ALTERNATE);



    when i call CreatePolygonRgn with arrayTemp i get the following


    error C2664: 'CreatePolygonRgn' : cannot convert parameter 1 from 'class CArray<class CPoint,class CPoint>' to 'struct tagPOINT *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


    how should i pass my arrary to this functions??????



    Similarly whenever i try to return CArrays i get cannot return errors as their are no members defined to copy and return the whole array??? that means i cant return CArrays?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    BOOL CreatePolyPolygonRgn( LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode );

    lpPoints
    Points to an array of POINT structures or an array of CPoint objects that defines the vertices of the polygons.


    An array is just that, an array.

    POINT points[5];
    CPoint cpoints[5];

    These are arrays with 5 elements.

    If you use special types like CArray, you will have to use their
    accessor functions.

    Look it up in the helpfile, I think GetData() will suit your needs.






    const TYPE* GetData( ) const;

    TYPE* GetData( );

    Return Value

    A pointer to an array element.

    Parameters

    TYPE

    Template parameter specifying the type of the array elements.

    Remarks

    Use this member function to gain direct access to the elements in an array. If no elements are available, GetData returns a null value.

    While direct access to the elements of an array can help you work more quickly, use caution when calling GetData; any errors you make directly affect the elements of your array.




    Example:

    rgn.CreatePolygonRgn( arrayTemp.GetData(), count, ALTERNATE );
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Also, this


    template< class TYPE, class ARG_TYPE > class CArray : public CObject

    Parameters

    TYPE

    Template parameter specifying the type of objects stored in the array. TYPE is a parameter that is returned by CArray.

    ARG_TYPE

    Template parameter specifying the argument type used to access objects stored in the array. Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.


    makes me believe it should be

    CArray<CPoint , CPoint& > arrayTemp;
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Unregistered
    Guest
    when i use it like this,

    CArray<CPoint , CPoint& > areaTemp1;
    rgn.CreatePolygonRgn(areaTemp1, count, ALTERNATE);


    just to let you know, it get the same error:

    error C2664: 'CreatePolygonRgn' : cannot convert parameter 1 from 'class CArray<class CPoint,class CPoint &>' to 'struct tagPOINT *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


    The other GetData() solution is not giving errors, i will tell you if it deos not work properly. Thankx.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Hi

    this should work:
    Code:
       CArray<CPoint, CPoint> arr;
       arr.Add(CPoint(10,10));
       arr.Add(CPoint(20,20));
       arr.Add(CPoint(20,10));
       CRgn region;
       region.CreatePolygonRgn(arr.GetData(), arr.GetSize(), 1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing / Returning a Boolean (Help)
    By EDB in forum C++ Programming
    Replies: 5
    Last Post: 02-17-2008, 02:56 PM
  2. Passing & Returning Arrays
    By jeffdavis_99 in forum C++ Programming
    Replies: 10
    Last Post: 04-02-2005, 06:44 PM
  3. returning struct and passing as an argument
    By ronin in forum C Programming
    Replies: 4
    Last Post: 06-07-2003, 12:21 PM
  4. Passing And Returning Values
    By neo6132 in forum C Programming
    Replies: 1
    Last Post: 04-19-2003, 11:24 PM
  5. Passing & Returning Strings from Functions
    By nisaacs in forum C Programming
    Replies: 1
    Last Post: 01-30-2002, 05:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21