C++DLL字符参数
C++ DLL char paramteters
我想从c程序中调用这个c++函数。我想使用char*errorMessage返回一条错误消息。当我在代码中执行返回errorMessage时,我会在返回后在C应用程序中获得char指针。但是,如果我尝试errorMessage = SafeStringHeap(string("File name was empty."));
,我在C应用程序中总是得到一个空指针。
我试图用c应用程序中的以下文本调用我的函数:
char* errorMessage = NULL;
TAFMessage = (*TAFParseMessageFile)(NULL, errorMessage);
功能:
static char* SafeStringHeap(string message)
{
//Save string on the heap
char * cstr = new char[message.length() + 1];
strcpy_s(cstr, message.length() + 1, message.c_str());
return cstr;
}
extern "C" __declspec(dllexport) const char* TAFParseMessageFile(const char* fileName, char* errorMessage)
{
if (fileName == NULL)
{
errorMessage = SafeStringHeap(string("File name was empty."));
return errorMessage;
}
return NULL; // TODO: set errorMessage
}
受制于上面提出的其他问题。尝试将errorMessage参数更改为char**(指向char指针的指针),然后执行:
*errorMessage = SafeStringHeap(...)
当调用函数pass&errorMessage
相关文章:
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- 如何解决一元"*"(有"字符")错误的无效类型参数?
- OpenCL 内核参数中的字符***?
- 无法将参数 1 从 WCHAR 转换为常量字符 *
- 如何将常量字符*作为参数传递给LPCSTR参数?
- 从常量字符*、字符*参数到标准::字符串的直接转换接口
- 在 Windows 中使用 boost::p rogram_options 从命令行参数读取 Unicode 字符
- (C/C++)fscanf_s从txt文件以字符形式读取数组时缺少整数参数错误
- 通过像printf这样的可变参数函数传递一个带有常量字符*转换函数的类
- 如何将从第 2 个字符开始的字符串作为函数中的参数传递以进行递归,并约束数据 tiee 是函数中的字符串?
- 常量字符[] 默认函数参数
- 如何将二维数组类型字符(字符串)作为函数参数传递?
- 显式(布尔值)可以作用于字符文字参数的长度吗?
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 字符串参数常量字符* 和常量 wchar_t*
- 为什么静态常量字符 * const 变量在为左值时可绑定到右值引用参数
- q致命参数:将 QString 转换为常量字符* 会导致警告"format string is not a string literal"
- std::string 参数是如何从原始字符数组文本传递的
- 将文本字符串作为常量字符 * 参数传递会导致代码分析器错误
- 可变参数字符列表的模板参数推导