array <Byte>^ to unsigned char*

Z

zon7mail

I've two functions. One is managed and receives an array, and the other
is unmanaged and receives a pointer, just like this
class A
{
int Foo(unsigned char* m){};
...
}

ref class B
{
int Boo(array< Byte >^ n){};
...
}

Is there anyway to call the function Foo from Boo passing n directly?
 
C

Carl Daniel [VC++ MVP]

I've two functions. One is managed and receives an array, and the
other is unmanaged and receives a pointer, just like this
class A
{
int Foo(unsigned char* m){};
...
}

ref class B
{
int Boo(array< Byte >^ n){};
...
}

Is there anyway to call the function Foo from Boo passing n directly?

Yes. Get a pin_ptr<Byte> that references the first byte of n and pass it to
Foo

using namespace System;

struct A
{
int Foo(unsigned char* m)
{
return *m;
}
};

ref class B
{
A* m_pA;
int Boo(array< Byte >^ n)
{
pin_ptr<unsigned char> pn = &n[0];
return m_pA->Foo(pn);
}
};

-cd
 
P

Paul E Collins

int Boo(array< Byte >^ n){};

Can someone tell me what this ^ means? I'm still using the C# 1.x
compiler (occasionally 2.x) and I only know ^ as the exclusive-or
operator.

Eq.
 
C

Carl Daniel [VC++ MVP]

Paul said:
Can someone tell me what this ^ means? I'm still using the C# 1.x
compiler (occasionally 2.x) and I only know ^ as the exclusive-or
operator.

This questsion was misposted - it's about C++/CLI, where the ^ operator is
used to derefence a "tracking pointer". It's roughly analogous to the '.'
in C# between an object reference and a member name.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top