- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 CLR DLL,用作与不同处理器类型的设备进行通信的接口(interface)。当从 C# 测试程序调用时,DLL 已经过测试并按预期工作。
在 C++/CLI 测试程序中,我无法将要放入缓冲区的值作为读取函数(在 dll 中)中的参数传递。
[更新]
这里 是我在 dll 中使用的函数的声明:
//changed pointers to arrays
bool connect(uint procType, String^ commPort);//Works as expected
bool read(uint16 addr, array<uint8>^% buf, uint bufSize, uint8 page);//data is not put into buf
bool write(uint16 addr, array<uint8>^% buf, uint bufSize, uint page);//Unknown behavior (cannot read to varify)
void close(void);//works as expected
[更新]
这里是C++/CLI测试程序:
using namespace System;
using namespace ProcessorInterfaceCLR;//namespace in dll
int main(int argc, char * argv[])
{
ProcessorCLR proc;
/* connect to device */
bool is_connected = proc.connect(1, "COM3");
if (is_connected)/* connect successful */ //Connect passes and fails when expected
{
unsigned short addr = 0x1000; //test address
const unsigned int size = 10;
array<Byte>^ buf = gcnew array<Byte>(size);// <-------- init managed array
/* read the data at the location */
bool retval = proc.read(addr, buf, size, 0/*page*/); //retval == true
//buf == {0,0,0...}, This is not the correct data
/* close comm when done */
proc.close();
}
return 0;
}
问题是
read()
应该将字节放在缓冲区中,而是将数据放在缓冲区中全为0。
[更新]
这里是我在dll中读取函数的实现。它将托管数组转换为非托管数组,并将其传递给包装在 cli dll 中的 c++ 函数。
/*
Reads data from the device into the given buffer. */
bool ProcessorCLR::read(uint16 addr, array<uint8>^% buffer, uint size, uint8 page)
{
pin_ptr<uint8> buf = &buffer[0];
return proc->read(addr, buf, size, page);
}
我通过注释掉对 proc->read()
的调用来对此进行测试并添加 buf[0] = 1
并且我能够获得返回值。
所以,
问题是数组,虽然 proc->read() 通常会更改非托管数组中的值,但它不会更改托管数组的 pin_ptr 的值大批。
问题已在上次更新中解决。我不得不将非托管阵列切换为托管阵列
并添加
%
指定将传递引用的运算符。
最佳答案
为了解决我的问题,我必须:
将 c++/cli dll 中的非托管数组切换为托管数组,然后使用 pin_ptr 在 dll 的内部函数中像非托管数组一样使用它们。
将 %
运算符添加到托管数组参数以指定它们将通过引用传递。
有关详细信息,请参阅我的问题。
关于.net - 如何在 C++/CLI 程序和 C++/CLI DLL 之间传递字节数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26895555/
我刚刚用 java-swing 为我写了一个桌面时钟,我希望每次登录时该时钟都运行。 为此,我将我的 jar 文件添加到 start 文件夹,我让时钟开始运行。 但我的问题是 - 任务栏中显示的图标允
我正在尝试编写一个程序来检查用户是否上传了新视频。我想让它成为一项后端工作,不断检查用户最近的视频,然后使用我的应用程序向我的用户发送推送。有关于这个问题的任何文档或示例代码吗?我完全不知道从哪里开始
我正在为我的 Raspberry Pi 编写一个程序,该程序由两个主要部分组成: 使用 Spotify-API“Libspotify”搜索音乐并播放音乐的 C 程序。 一个在 apache2 We
我做了一个C++生成命令行并将命令转发给它的程序。目前,我正在将 cmd 控制台的输出发送到一个文件,并在我的 C++ 程序中读取它。但我想让它与管道一起工作。 是否可以从 Windows cmd 行
是否可以使用 C 程序和 malloc 找出处理器的页面大小?而不是使用 sysconf() 调用? 最佳答案 如果你可以#include一些linux内核头文件,你可以在中找到宏PAGE_SIZE
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我想实现一个算法: 从 Ruby on Rails 应用程序获取数据库对象作为输入, 对输入执行计算, 根据计算查询 Rails 数据库, 并根据查询生成一组有序结果。 我将用 C(也许是 Objec
我今天的任务是创建一个 Python 脚本(例如 A.py),它可以执行以下操作: 启动 C 程序(例如 CProg)并传递一些参数 启动另一个 Python 脚本(例如 B.py)并传递其他参数 加
我有一个在后台运行的 .NET 程序,需要创建一个可以与该程序通信的 Windows Shell 扩展。起初我以为我会在 .NET 中创建我的 Shell Extension,并使用 IpcServe
Python 程序做前端工作,C 程序做后端工作。它们中的每一个都是一个单独的过程。 Python 进程充当主进程,向 C 进程发送信号和事件。 C 进程生成统计信息、计数器和信息,这些信息被发送回
如何与 shell 脚本共享 C 头文件? shell 脚本通过命名管道与 C 程序通信。让我们假设 C 头文件中定义的枚举 SAMPLE_ONE 由 C 程序写入管道。 shell 脚本从管道中读出
我有一些客户/候选人提示我的程序不能在他们的 Windows 7 64 位版本上运行(已通过屏幕截图确认)。错误很奇怪,例如: in the trial version i am getting a
这个问题在这里已经有了答案: Why SDL defines main macro? (2 个答案) 关闭 7 年前。 我在 Windows 操作系统下使用 QT Creator 的简单程序中使用
我的导师给了我们一个基本的 C shell 来扩展,我目前正在努力让 shell 在用户在命令行中输入“cd [directory]”时更改目录。我已经得到它来停止段错误,但它不会更改目录。谁能告诉我
我以前有过这个工作,但我使用的是指针。 getenv() 不断崩溃,所以我使用 sprintf() 复制了结果。现在我想用 : 删除并只打印第一次出现的地方。请帮忙! #include #inclu
你好,我第一次使用 C primer plus book 学习 C,然后在第 16 章关于 C11 标准的 _Generic 我在 Eclipse c/c++ 中编写了一个程序并构建它产生了 8 个错
我正在尝试从另一个 C 程序执行 python 程序,其中 py 脚本的返回值为 int array[3] 我可以从 python 退出代码中获取这个数组吗?? 编辑:如果问题不清楚,我可以将 pyt
// The countChicken() method should count the number of occurrences of the word chicken (or some oth
我已经通过 ZMQ 使用同一类成功地从 C# 和 C++ 程序传输数据,其中 C++ 类是数据定义,编译器幸运地将字节数组屏蔽到类。 我如何在 C# 和 Node.js 程序之间做同样的事情?我认为他
任何人都可以为我指明有关 makefile 如何工作以及如何使用 eclipse 从头开始基本程序的好教程的方向吗?我正在为 fedora 和 C++ 使用 eclipse 3.4.1 版。提前致
我是一名优秀的程序员,十分优秀!