2

I have a c++ function that look like this :

int Compression::DecompressPacket(const void* inData, int inLength, void* outData, int outLength)
{
    int headerLength = ComputeDataHeaderLength(inData);
    return DecompressDataContent(static_cast<const unsigned char*>(inData) + headerLength, inLength - headerLength, outData, outLength);
}

The fonction is inside a class which is inside a c++ library.

In the other hand, I need to call this fonction on my c# application. The fonction ask me to enter parameters of types : "void*, int, void*, int".

When I try to make a void* in an unsafe function,

unsafe private void lstbox_packets_SelectedIndexChanged(object sender, EventArgs e)
{
   [...]
   byte[] value = byteValuePackets[lstbox_packets.SelectedIndices[0]];    
   void* pValue = &value;
   [...]
}

I get the error :

Error 8 Cannot take the address of, get the size of, or declare a pointer to a managed type ('byte[]')

I'm not very familiar with c++ and pointer but how i am suppose to pass a void* type in c# ?

1 Answer 1

2

You shouldn't take the address of value, and also you have to use fixed statement:

fixed (void* pValue = value)
{
    //...
}
Sign up to request clarification or add additional context in comments.

2 Comments

Here's the link for the reference to fixed: msdn.microsoft.com/en-us/library/…
Sorry, you are right. The styling on the fixed keyword did not make it apparent it is also a link :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.