问题
I am trying to pass bytes by reference from C# such that I can call the atomic operation InterlockedOr8 on them. I have the following static library in C++:
Bitwise.h:
char EightBitOr(char volatile* destination, char value);
Bitwise.cpp:
#include "Bitwise.h"
char EightBitOr(char volatile* destination, char value)
{
return InterlockedOr8(destination, value);
}
I am calling it from this C++/CLI wrapper DLL:
Wrapper.h:
#include "..\Bitwise\Bitwise.h"
using namespace System;
namespace Wrapper {
public ref class Bitwise
{
public:
static char InterlockedEightBitOr(volatile char* destination, char value);
};
}
Wrapper.cpp:
#include "Wrapper.h"
char Wrapper::Bitwise::InterlockedEightBitOr(volatile char* destination, char value)
{
return EightBitOr(destination, value);
}
I am trying to call the wrapper from a .NET 5.0 (Core) C# Console Application as follows:
var map = new byte[268435456];
Bitwise.InterlockedEightBitOr(ref map[0], (byte)1);
But I get the following error:
CS0570 'Bitwise.InterlockedEightBitOr(sbyte*, sbyte)' is not supported by the language
I also noticed the wrapper has translated the method signature into sbyte Bitwise.InterlockedEightBitOr(sbyte* destination, sbyte value);
whereas I'd much rather pass unsigned bytes and I am not sure how to change this behavior. Anyways, I was wondering if anyone knew if there is any way I can pass bytes by reference into this CLI wrapper? What changes would I need to make?
来源:https://stackoverflow.com/questions/65998398/passing-bytes-by-reference-from-c-sharp-into-c-cli-wrapper-to-call-the-interlo