arrays / pointers in managed classes 
Author Message
 arrays / pointers in managed classes

I used to do this in VC++6, but now I'm kinda stuck:

[class member]
        HANDLE Handles[2];
[in member function]
        WaitForMultipleObjects(2, Handles, FALSE, INFINITE);

This doesn't work in a managed class: apparently an array name, even
with an explicit __nogc in the array declaration, is no longer the
same as a pointer to its first element?

        HANDLE Handles __nogc [2];
        WaitForMultipleObjects(2, Handles, FALSE, INFINITE);

error C2664: 'WaitForMultipleObjects' : cannot convert parameter 2
from 'HANDLE [2]' to 'const HANDLE * '

And when I write

        WaitForMultipleObjects(2, &Handles[0], FALSE, INFINITE);

the compiler tells me that &Handles[0] is a __gc pointer, despite the
__nogc in the array declaration ???

Do I really have to resort to allocating memory for the array myself,
like this?

        HANDLE __nogc *Handles;
        Handles = (HANDLE __nogc *)malloc(2 * sizeof(HANDLE));
        Handles[0] = ...
        Handles[1] = ...
        WaitForMultipleObjects(...);
        free(Handles);

Or won't this work either?



Sat, 10 Sep 2005 22:56:51 GMT  
 arrays / pointers in managed classes
Lucvdv,

Quote:
> I used to do this in VC++6, but now I'm kinda stuck:

> [class member]
> HANDLE Handles[2];
> [in member function]
> WaitForMultipleObjects(2, Handles, FALSE, INFINITE);

> This doesn't work in a managed class: apparently an array name, even
> with an explicit __nogc in the array declaration, is no longer the
> same as a pointer to its first element?

> HANDLE Handles __nogc [2];
> WaitForMultipleObjects(2, Handles, FALSE, INFINITE);

> error C2664: 'WaitForMultipleObjects' : cannot convert parameter 2
> from 'HANDLE [2]' to 'const HANDLE * '

> And when I write

> WaitForMultipleObjects(2, &Handles[0], FALSE, INFINITE);

> the compiler tells me that &Handles[0] is a __gc pointer, despite the
> __nogc in the array declaration ???

> Do I really have to resort to allocating memory for the array myself,
> like this?

> HANDLE __nogc *Handles;
> Handles = (HANDLE __nogc *)malloc(2 * sizeof(HANDLE));
> Handles[0] = ...
> Handles[1] = ...
> WaitForMultipleObjects(...);
> free(Handles);

> Or won't this work either?

No. You only have to pin the object the array is declared in first:

WhateverClass __pin* pinnedThis = this;
WaitForMultipleObjects(2, pinnedThis->Handles, FALSE, INFINITE);

Or something like that.

--
Tomas Restrepo



Sun, 11 Sep 2005 01:54:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. qsorting & managing struct arrays, pointer arrays

2. Embed template class pointer inside managed class

3. Managed array of managed arrays of char

4. pointer to managed array

5. Managed arrays and pointer arithmetic

6. How to manage array of __gc pointers

7. Reference to an unmanaged pointer in a managed class

8. static array in a manage class

9. How to declare a managed class pointer from unmanaged c++

10. Managed class returning an unmanged pointer

11. Pointer to a manages class

12. Managed class arrays

 

 
Powered by phpBB® Forum Software