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.
我正在调用 LoadTypeLib 以在 C++/CLI 中加载非托管类型库。我需要将一些代码区域编译为托管,将一些代码区域编译为非托管(本机),并形成一个混合模式类库作为可执行文件。
我需要托管和非托管(本机)哪一部分才能分别编译为托管和本机?
#pragma managed
更喜欢#pragma managed与 push 和 on/off 一起使用,然后是 pop,#pragma unmanaged实际上是毫无用处的。
#pragma unmanaged
不要使用 #pragma managed - 它被认为是“邪恶的”,可能会导致 DLL 初始化/关闭出现问题。
我建议将一些文件显式编译为托管文件 (/clr),而将一些文件编译为本机文件 (没有 /clr)。您还可以有两个预编译的标头 - 一个用于托管,一个用于本机。