从本机类方法调用托管函数是否安全?

时间:2013-12-11 14:30:33

标签: .net c++-cli mixed-code

我有带有本地接口(导出类)的C ++ DLL,它是用/ clr开关编译的。导出类的某些方法具有...参数。编译器在此类上显示C4793警告:函数被编译为本机代码。

// ExportedClass.h
class LIBRARY_API ExportedClass
{
public:
    void Method(const char* format, ...);
};

// ExportedClass.cpp

void ManagedFunction()
{
    String^ s = gcnew String(L"");    // OK
}

void ExportedClass::Method(const char* format, ...)
{
    // Not allowed: the function is native
    // String^ s = gcnew String(L"");

    // Call ManagedFunction instead:
    ManagedFunction();
}

由于该类被编译为本机,我不能直接在类方法中使用托管代码。但是,我可以调用托管函数,如代码示例所示。这样做是否安全?

0 个答案:

没有答案
相关问题