I
Ioannis Vranos
I have been checking C++/CLI lately by using VC++ 2005 Express Beta 1
(should be called Alpha though).
In managed extensions we could pass managed pointers to functions taking
unmanaged pointers as parameters by using __pin pointers:
__gc class whatever
{
// ...
};
template<class T>
void somefun(T *p)
{
// ...
};
int main()
{
whatever *p=__gc new whatever;
whatever __pin *pp=p;
somefun(pp);
// ...
}
How can this handle to pointer conversion take place in C++/CLI? The
following does not seem to work:
ref class managed
{
};
int main()
{
using namespace stdcli::language;
managed ^h=gcnew managed;
pin_ptr<managed>p=h;
}
C:\c>cl /clr temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40607.16
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.
temp.cpp
temp.cpp(12) : error C3833: 'managed' : invalid target type for pin_ptr
Cannot declare pin_ptr to a handle type. Consider declaring
pin_ptr to one of the members of 'managed'
C:\c>
Best regards,
Ioannis Vranos
(should be called Alpha though).
In managed extensions we could pass managed pointers to functions taking
unmanaged pointers as parameters by using __pin pointers:
__gc class whatever
{
// ...
};
template<class T>
void somefun(T *p)
{
// ...
};
int main()
{
whatever *p=__gc new whatever;
whatever __pin *pp=p;
somefun(pp);
// ...
}
How can this handle to pointer conversion take place in C++/CLI? The
following does not seem to work:
ref class managed
{
};
int main()
{
using namespace stdcli::language;
managed ^h=gcnew managed;
pin_ptr<managed>p=h;
}
C:\c>cl /clr temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40607.16
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.
temp.cpp
temp.cpp(12) : error C3833: 'managed' : invalid target type for pin_ptr
Cannot declare pin_ptr to a handle type. Consider declaring
pin_ptr to one of the members of 'managed'
C:\c>
Best regards,
Ioannis Vranos