I have both of these in my class
我的课上有这两个
#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>
and I have
和我有
using namespace msclr::interop;
I am using it to marshal String^ to string. Here is one example.
我用它来元帅字符串^字符串。这是一个例子。
string ProgReleaseType = marshal_as<std::string>(CurrentSubKey->GetValue("ReleaseType", NULL)->ToString());
When I build, I get this error.
当我构建时,我得到这个错误。
Error 53 error C4996: msclr::interop::error_reporting_helper<_To_Type,_From_Type,false>::marshal_as': This conversion is not supported by the library or the header file needed for this conversion is not included. Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method. C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\msclr\marshal.h 237
When I go into the marshal.h and read through line 237 is says to please use a marshal_context. I thought I was. I don't get what it doesn't like.
当我进入元帅。读第237行是为了使用marshal_context。我认为我是。我不知道它不喜欢什么。
3 个解决方案
#1
1
Use a marshal context:
使用一个元帅上下文:
msclr::interop::marshal_context context;
string ProgReleaseType = context.marshal_as<std::string>(CurrentSubKey->GetValue("ReleaseType", NULL)->ToString());
#2
2
I'm unable to reproduce this error as described. That is the error I get if I include msclr\marshal.h
but not msclr\marshal_cppstd.h
. Double-check you're including it, or perhaps include it explicitly as the very first line in your cpp file.
我无法再现所描述的这个错误。如果我包含msclr\marshal,就会得到这个错误。h但不是msclr \ marshal_cppstd.h。再次检查您是否包含它,或者可能将它显式地包含为cpp文件中的第一行。
Here's my test application:
这是我的测试应用程序:
#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>
using namespace msclr::interop;
using namespace System;
using namespace System::Diagnostics;
int main(array<System::String ^> ^args)
{
String^ str = "Something";
std::string stdstr = marshal_as<std::string>(str);
stdstr[4] = '-';
// Convert back to managed for printing.
Debug::WriteLine(marshal_as<String^>(stdstr));
return 0;
}
Output:
输出:
Some-hing
Some-hing
#3
1
I hope this answer will help you.
我希望这个答案能对你有所帮助。
-
Add header
添加标题
#include <msclr\marshal_cppstd.h>
-
Here is sample code for String^ to string (standard string)
这里的示例代码字符串^字符串(字符串)标准
String^ str ="Sample string"; msclr::interop::marshal_as<std::string>(str)
#1
1
Use a marshal context:
使用一个元帅上下文:
msclr::interop::marshal_context context;
string ProgReleaseType = context.marshal_as<std::string>(CurrentSubKey->GetValue("ReleaseType", NULL)->ToString());
#2
2
I'm unable to reproduce this error as described. That is the error I get if I include msclr\marshal.h
but not msclr\marshal_cppstd.h
. Double-check you're including it, or perhaps include it explicitly as the very first line in your cpp file.
我无法再现所描述的这个错误。如果我包含msclr\marshal,就会得到这个错误。h但不是msclr \ marshal_cppstd.h。再次检查您是否包含它,或者可能将它显式地包含为cpp文件中的第一行。
Here's my test application:
这是我的测试应用程序:
#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>
using namespace msclr::interop;
using namespace System;
using namespace System::Diagnostics;
int main(array<System::String ^> ^args)
{
String^ str = "Something";
std::string stdstr = marshal_as<std::string>(str);
stdstr[4] = '-';
// Convert back to managed for printing.
Debug::WriteLine(marshal_as<String^>(stdstr));
return 0;
}
Output:
输出:
Some-hing
Some-hing
#3
1
I hope this answer will help you.
我希望这个答案能对你有所帮助。
-
Add header
添加标题
#include <msclr\marshal_cppstd.h>
-
Here is sample code for String^ to string (standard string)
这里的示例代码字符串^字符串(字符串)标准
String^ str ="Sample string"; msclr::interop::marshal_as<std::string>(str)