I asked ChatGPT to convert the c# code to VC++....
using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
Image^ MyImg;
ImageConverter^ converter = gcnew ImageConverter();
array<Byte>^ byteArray = safe_cast<array<Byte>^>(converter->ConvertTo(MyImg, array<Byte>::typeid));
... and according to OP the code works.