0

Возникла ошибка при компилировании кода с помощью marshal.
Код:

#include <msclr\marshal_windows.h>
#include <msclr\marshal.h>
#include <string>
//...
short year,day;
String^ y;
String^ d;
char* temp;
marshal_context^ marshal = gcnew marshal_context();
temp = marshal->marshal_as<char*>(d);
if (day==0) d="";
if (day!=0) temp=_itoa(day,temp,10);
d = marshal->marshal_as<System::String^>(temp);
temp = marshal->marshal_as<char*>(y);
temp=_itoa(year,temp,10);
y=marshal->marshal_as<System::String^>(temp);

Ошибки: error C4996:'msclr::interop::error_reporting_helper<_To_Type,_From_Type>::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.
(Ссылается на marshal.h, на строку с макросом, обозначающим эту ошибку)

Как исправить?
Visual Studio 2010
P.S: #pragma warning(disable:4996) и т.п. почему-то не работают.

1
  • Ваш template<> не поддерживает указаный тип. Хоть строку с ошибкой укажите что б не гадать. p. s. #pragma warning ошибки не выключает.
    – nick_n_a
    19 авг 2016 в 9:31

1 ответ 1

0

Ошибка в строках:

temp = marshal->marshal_as<char*>(d);

и

temp = marshal->marshal_as<char*>(y);

Согласно документации ошибка C4996 возникает при попытке преобразования типов которые не поддерживаются. А таблица преобразования о невозможности преобразования к типу char*.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.