Works, but bleech, you need untrusted code permission. If you can compile the C++ code as
a managed assembly (C++/CLI), then you would use
public ref class A
{
HRESULT MyFunc(System::Int32% intbyref) { intbyref = 42; return S_OK; }
}
which has almost the identical caller interface, but no need for DllImport (use a managed
reference instead) and needs no special permissions (since this code will compile with
/clr:safe)