第8篇c++Expression: (L“Buffer is too small“ 0
c#调用c++库报错
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: ...ration_oqxa2\mysql_operation\bin\x64\Debug\mysql_operation.exe
File: minkernel\crts\ucrt\inc\corecrt_internal_string_templates.h
Line: 81
Expression: (L"Buffer is too small" && 0)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
导出库时使用不正确
char* __stdcall ImgRotate(char* charstr, int degree){std::string imgPath = charstr;//const char* chardata = c_Obj.ImgRotate(imgPath, degree).c_str();std::string str_data = c_Obj.ImgRotate(imgPath, degree);char* charArr = new char[str_data.length() + 1];// strcpy(charArr, str_data.c_str());strcpy_s(charArr, sizeof(charArr), str_data.c_str());return charArr;}
strcpy_s(charArr, sizeof(charArr), str_data.c_str());缓冲区移除
直接使用strcpy
char* __stdcall ImgRotate(char* charstr, int degree){std::string imgPath = charstr;//const char* chardata = c_Obj.ImgRotate(imgPath, degree).c_str();std::string str_data = c_Obj.ImgRotate(imgPath, degree);char* charArr = new char[str_data.length() + 1];strcpy(charArr, str_data.c_str());// strcpy_s(charArr, sizeof(charArr), str_data.c_str());return charArr;}
预处理器里面添加: _CRT_SECURE_NO_WARNINGS,编译则不会报错