使用C++从Windows应用程序向dll方法传递字符串
Passing string to dll mehods from Windows application using C++
我们目前正在创建一个简单的Windows应用程序,该应用程序将加载dll文件并在dll中调用不同的方法。
以下是状态:
- Windows应用程序设计-->确定
- 从UI单击加载.dll按钮-->确定
- 从UI单击按钮时调用.dll文件中的方法-->确定
- 单击-->NOK按钮,将字符串传递给.dll方法
.dll中的方法
sendReqXml(char *xmlString)
{
printf("nsendReqXml() +n");
//we will write xmlstring in file here to check what we received from UI console
FILE *out;
if ((out = fopen("C:\Users\20105388\Desktop\textfile.txt", "w")) != NULL)
{
fprintf(out, "the range is '%s'n", xmlString);
fclose(out);
}
//.... then proceed further
}
UI控制台方法
private: System::Void button2_Click(System::-Object^ sender, System::EventArgs^ e)
{
char *xmlFile = "I am sending text from UI";
DLLSEND _SENDXML;
_SENDXML = (DLLSEND) GetProcAddress(hGetProcIDDLL, "sendReqXml");
if (_SENDXML != NULL)
{
_SENDXML(xmlFile);
}
}
我们只是试图在sendReqXml方法的文件中打印一个字符串,以检查我们从UI接收到的内容。
fprint(out,"the range is '%s'n", xmlString);
无论我们从UI传递什么字符串,上面的方法都会在文件中写入下面的输出
**the range is '„¹&Z'**
这是不正确的,那么有人能帮助解决这个问题吗?
注意:
当使用命令行时,上面的方法可以很好地工作,并在文件中写入正确的输出。
谢谢你的帮助。
我认为您正在尝试调用托管c++(c++/cli)上的本机c/c++dll函数。正确的那么…你试过PInvoke吗?参考本页https://msdn.microsoft.com/en-us/library/ms235282.aspx
相关文章:
- 有哪些有效的方法可以消除一组 100 万个字符串>重复数据?
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 具有字符串化的可变参数宏的现代/通用方法
- 接收字符串并使用它来调用方法C++
- 如何分隔字符串并将标记传递给方法
- 是否有通用方法可以找到任何以 null 结尾的字符串的长度?
- 当映射包含字符串向量作为值时,从值中获取键的有效方法
- 在 C++11 中字符串化变量名称的替代方法
- 连接和压缩标准::vector<std::字符串的最佳方法>
- Esp8266 & Nodemcu:返回请求字符串的方法
- 将位字符串转储到二进制文件的最佳方法是什么
- 有没有一种 STL 方法可以找到字符串的所有排列,给出一个以 C++ 为单位的大小?
- 如何将字符串从 C++/CLI 方法返回到调用它的非托管C++
- 创建字符串数组的有效方法
- 如何使用字符串::replace方法写入文件
- 是否有更有效的方法来生成日期的REGEX字符串
- C++-将对象(如字符串)映射到表中成员函数的正确方法
- 有没有更快的方法从成员函数返回格式化字符串
- 有没有一种方法可以在不复制数据的情况下从string_view创建字符串流
- 从c++中的类指针对象调用方法(字符串)