Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从本机类方法调用托管函数安全吗? 我有C++本地接口(出口类),它是用/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(); }_.net_C++ Cli_Mixed Code - Fatal编程技术网

.net 从本机类方法调用托管函数安全吗? 我有C++本地接口(出口类),它是用/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(); }

.net 从本机类方法调用托管函数安全吗? 我有C++本地接口(出口类),它是用/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(); },.net,c++-cli,mixed-code,.net,C++ Cli,Mixed Code,由于该类是编译为本机的,因此我不能在类方法中直接使用托管代码。但是,我可以调用托管函数,如代码示例所示。这样做安全吗?您正在玩一个非常危险的游戏,需要先加载并初始化CLR,然后才能执行托管函数。现在,您可能是无意中得到了它,如果需要,C++/CLI编译器将创建一个存根来完成这项工作。那个存根不便宜。您也无法控制得到的CLR版本。使用COM或自己托管CLR是安全版本。@HansPassant:此库使用/cli编译,并通过链接器依赖项列表从客户端引用。AFAIK,这意味着在进程启动时加载CLR。这是

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

您正在玩一个非常危险的游戏,需要先加载并初始化CLR,然后才能执行托管函数。现在,您可能是无意中得到了它,如果需要,C++/CLI编译器将创建一个存根来完成这项工作。那个存根不便宜。您也无法控制得到的CLR版本。使用COM或自己托管CLR是安全版本。@HansPassant:此库使用/cli编译,并通过链接器依赖项列表从客户端引用。AFAIK,这意味着在进程启动时加载CLR。这是正确的吗?