Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 C++ API 原型
void Func(int& size);
如何在 C# 中将其翻译为 P/Invoke?
据我所知,如果我使用
public static extern Func(ref int size);
,该函数将接收指向 int 而不是值的指针。
(哎呀......这意味着这是一个答案,而不是评论)。
当您从 C++ 调用它时,该函数也会收到一个指针。你认为引用是如何实现的?Func() 将该指针视为引用,因此它如何到达那里并不重要。