Asked by:
Pointer to a C++ array of 'hat' handles

Question
-
Hi,
I'm trying to store a series of WriteOnlyArray objects:
WriteOnlyArray<unsigned char,1U>^* pMessages=new WriteOnlyArray<unsigned char,1U>^[10];
The compiler throws a "array of handles is not allowed" error.
I've also been trying to store these on a std:queue using ->push with no success... I think these two problems are related.
Why isn't an array of handles allowed, and how to store an array of WriteOnlyArray s?
Sunday, July 15, 2012 5:46 AM
All replies
-
Why don't you create an Array of WriteOnlyArray?Sunday, July 15, 2012 2:32 PM
-
I bet it is due to ^ pointers needing reference counting support and plain C++ arrays not being ref counting friendly.Sunday, July 15, 2012 8:29 PM
-
Hi Todd2010,
From the MSDN documentation, we find these statement: “C++/CX supports authoring function parameters whose type is a read/write array (Platform::Array) or a write-only array (Platform::WriteOnlyArray). You can't define a WriteOnlyArray array, but you can declare a function parameter type as WriteOnlyArray so that the Windows Runtime can efficiently pass an Array by reference.” For more information about defining and declaring WriteOnlyArray in C++/CX, please refer to this page: http://msdn.microsoft.com/en-us/library/hh700105(v=vs.110).aspx.
The following code fragment declares a function whose first parameter is a WriteOnlyArray<T>. The function is called by using an Array<T> object even though the function parameter type is WriteOnlyArray<T>:
using namespace Platform;
void MyFunc2(WriteOnlyArray<int>^ a, int* actual) {
*actual = 0;
if (ai->Length > 2) {
a[0] = 0;
a[1] = 1;
*actual = 2;
}
};
int main() {
int used = 0;
auto ai = ref new Array<int>(5);
MyFunc2(ai, &used); // Array<T>^ has an implicit conversion to WriteOnlyArray<T>^
return used;
}
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Jesse Jiang Thursday, July 19, 2012 6:56 AM
- Unproposed as answer by Todd2010 Thursday, July 19, 2012 7:17 AM
Monday, July 16, 2012 11:18 AM -
Hi Jesse,
Thanks for the reply, but this is not related to my question. However, you are right that you can't explicitly declare a WriteOnlyArray.
I receive the same error if I try to declare an array of "Array".
Likewise, the std::queue->push method refuses to take either an Array or WriteOnlyArray as a type... my question is 'why'?
Thanks.
Thursday, July 19, 2012 7:19 AM -
Hi Todd2010,
I have tried the following lines. These codes can be compiled successfully:
Array<unsigned char>^ chararray; chararray=ref new Array<unsigned char>(10); queue<unsigned char>* q= new queue<unsigned char>; q->push(chararray[0]);
While the complication may be fail if the type of the queue element is Array or WriteOnlyArray. Please refer to the following codes:Array<unsigned char>^ chararray=ref new Array<unsigned char>(3); queue<Array<unsigned char>^>* qa= new queue<Array<unsigned char>^>; qa->push(chararray);//error C2664 queue<WriteOnlyArray<int>^>* qw=new queue<WriteOnlyArray<int>^>; auto ai = ref new Array<int>(10); qw->push(ai);//error C2664
I hope this reply is helpful to you.
Best regards,
Helen Zhao [MSFT]
MSDN Community Support | Feedback to us
Thursday, July 19, 2012 8:55 AM