- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我正在将函数从 C++ DLL 导入到 C# 应用程序中。我能够导入一些功能,但不能导入其他功能。 C++ DLL 附带了一个 C++ 项目,展示了如何从 C++ 使用它。我想在 C# 中复制它,但我在编码方面遇到了问题。这是 C++:
头文件声明:
unsigned long __stdcall mfcs_initialisation(unsigned short serial);
unsigned long __stdcall mfcsez_initialisation(unsigned short serial);
unsigned char __stdcall mfcs_close(unsigned long handle);
unsigned char __stdcall mfcs_set_purge_on(unsigned long int handle);
unsigned char __stdcall mfcs_set_purge_off(unsigned long int handle);
unsigned char __stdcall mfcs_get_purge(unsigned long int handle,
unsigned char * c);
unsigned char __stdcall mfcs_get_status(
unsigned long int handle,
unsigned char * c);
unsigned char __stdcall mfcs_read_chan(
unsigned long int handle,
unsigned char canal,
float * pressure,
unsigned short * chrono);
unsigned char __stdcall mfcs_data_chan(
unsigned long int handle,
unsigned char canal,
unsigned char * unite,
unsigned short * max,
unsigned short * zero,
unsigned short * mesure,
unsigned short * chrono);
unsigned char __stdcall mfcs_get_serial(unsigned long int handle,
unsigned short * us);
unsigned char __stdcall mfcs_set_auto(
unsigned long int handle,
unsigned char canal,
float pcons);
unsigned char __stdcall mfcs_set_alpha(
unsigned long int handle,
unsigned char canal,
unsigned char alpha);
unsigned char __stdcall mfcs_set_manual(
unsigned long int handle,
unsigned char canal,
float pcons);
unsigned char __stdcall mfcs_set_zero(
unsigned long int handle,
unsigned char canal,
unsigned short zero);
unsigned char __stdcall mfcs_detect(unsigned short table[256]);
unsigned char __stdcall mfcsez_detect(unsigned short table[256]);
C++代码:
/* Define functions prototype */
typedef unsigned long(__stdcall *init)(int);
typedef unsigned char(__stdcall *purgeOn)(unsigned long handle);
typedef unsigned char(__stdcall *purgeOff)(unsigned long handle);
typedef unsigned char(__stdcall *serial)(unsigned long handle, unsigned short *serial);
typedef unsigned char(__stdcall *close)(unsigned long handle);
typedef unsigned char(__stdcall *setAuto)(unsigned long int handle, unsigned
char canal, float pcons);
typedef unsigned char(__stdcall *readChannel)(unsigned long handle, unsigned
char chan, float * pressure, unsigned short * chrono);
typedef unsigned char(__stdcall *setAlpha)(unsigned long int handle, unsigned
char canal, unsigned char alpha);
int main(int argc, char *argv[])
{
/* System settings variable definition */
float start_pressure = 70; //Pressure set (mbar) at the beginning
float target_pressure = 100; //Maximal pressure setpoint (mbar)
unsigned char pressureChannel = 1; //Selected channel (0 for all channels or put the channel number you would like to control)
HINSTANCE hGetProcIDDLL=NULL; // Define dll handler
/* Load DLL into memory */
hGetProcIDDLL = LoadLibrary(TEXT("mfcs_c.dll"));
/* Declare pointers on dll functions */
init dll_init;
purgeOn dll_purgeOn;
purgeOff dll_purgeOff;
serial dll_serial;
close dll_close;
setAuto dll_setAuto;
readChannel dll_readChannel;
setAlpha dll_setAlpha;
/* Link dll pointers with functions prototype */
dll_init = (init)GetProcAddress(hGetProcIDDLL, "mfcsez_initialisation");
dll_serial = (serial)GetProcAddress(hGetProcIDDLL, "mfcs_get_serial");
dll_purgeOn = (purgeOn)GetProcAddress(hGetProcIDDLL, "mfcs_set_purge_on");
dll_purgeOff = (purgeOff)GetProcAddress(hGetProcIDDLL, "mfcs_set_purge_off");
dll_close = (close)GetProcAddress(hGetProcIDDLL, "mfcs_close");
dll_setAuto = (setAuto)GetProcAddress(hGetProcIDDLL, "mfcs_set_auto");
dll_readChannel = (readChannel)GetProcAddress(hGetProcIDDLL, "mfcs_read_chan");
dll_setAlpha = (setAlpha)GetProcAddress(hGetProcIDDLL, "mfcs_set_alpha");
/* Define variables used for MFCS device */
unsigned long mfcsHandle;
unsigned short mySerial;
float read_pressure;
unsigned short chrono;
int loop_index;
if (hGetProcIDDLL != NULL) { // If dll loaded
std::cout << "mfcs_c.dll is loaded" << std::endl;
/* Initialize device */
if (dll_init != NULL) { // Check if function was properly linked to the dll file
/* Initialize the first MFCS in Windows enumeration list */
mfcsHandle = dll_init(0);
/* After the initialization we need to add a delay of 500ms to make sure that the USB communication is properly established */
Sleep(500);
std::cout << "MFCS initialized" << std::endl;
}
/* Read device serial number */
if (dll_serial != NULL) {
/*Get the serial number of the MFCS*/
dll_serial(mfcsHandle, &mySerial);
std::cout << "MFCS SN: " << mySerial << std::endl;
}
/* Set pressure regulation servitude coefficient */
if (dll_setAlpha != NULL) {
dll_setAlpha(mfcsHandle ,pressureChannel, 4); // Default value (just after power on) is 0
} // Alpha value has to be grather than 0 in order to regulate pressure
/* Change and read pressure every second until reaching 'target_pressure' value */
for (loop_index = int(start_pressure); loop_index<target_pressure; loop_index++){
dll_setAuto(mfcsHandle,pressureChannel,float(loop_index)); // Set required output pressure value
Sleep(1000); // Wait 1 s
dll_readChannel(mfcsHandle, pressureChannel, &read_pressure, &chrono); // Get the pressure value on the specified channel
std::cout << "Set pressure at: " << loop_index << "mbar" << "; Read pressure: " << read_pressure
<< "mbar" << std::endl; // Display pressure setpoint and channel pressure value
}
/* Close MFCS session */
if (dll_close != NULL) {
dll_close(mfcsHandle);
std::cout << "MFCS closed" << std::endl;
}
}
/* Release the DLL */
FreeLibrary(hGetProcIDDLL);
std::cout << "mfcs_c.dll unloaded" << std::endl;
/* Exit application */
system("PAUSE");
return EXIT_SUCCESS;
基本上,我已经尝试了很多导入函数的排列组合,以及任何包含无符号字符或指针的排列组合,但我不知道如何映射。
非常感谢 DAVID 插入我从我这边变得更有用。
注意:一个对我有帮助的示例是基于上面的 C++ 代码的清晰说明,用于拉入 mfcs_get_serial(unsigned long int handle, unsigned short * serial) 到 C#。
我不知道下面的代码有什么问题,它应该读取数字并将它们的值与位置放在一个成对的 vector 中,然后对它们进行排序并打印出位置。我用 sort 删除了部分 - 我认为问题就在那里,但我再次收到编译错误
我相信当您将两个 unsigned int 值相加时,返回值的数据类型将是 unsigned int。 但是两个 unsigned int 值相加可能会返回一个大于 unsigned int 的值。
我从左移得到的结果我找不到解释。 unsigned char value = 0xff; // 1111 1111 unsigned char = 0x01; // 0000 0001 std::c
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
根据:http://en.wikipedia.org/wiki/C_data_types您可以使用 unsigned short 类型或 unsigned short int 类型。但是它们之间有什么
我正在尝试在 arduino 草图中实现 CRC16。从网上拿到了crc.c文件,想试试看。我创建了其他文件以允许 crc.c 正确运行。这是我的文件。 crc.h: #ifndef CRC_C_ #
我正在尝试实现一个将存储相关索引的列表。但是,我在标题中提到的 for (index_itr = (list_size - numberOfEvents - 1) 处遇到错误。我在做什么错误,以及如何
这不是跨平台代码...所有内容都在同一平台上执行(即字节序是相同的......小字节序)。 我有这个代码: unsigned char array[4] = {'t', 'e', 's', '
我有一个 8 位 unsigned char vector 和一个 16 位 unsigned short vector std::vector eight_bit_array; std::vecto
这个问题在这里已经有了答案: Is subtracting larger unsigned value from smaller in C++ undefined behaviour? (2 个答案
这个问题已经有答案了: Difference between unsigned and unsigned int in C (5 个回答) 已关闭 6 年前。 在 C 语言中,unsigned 之间有
我遇到了一个我不太理解的警告。该警告是通过比较我认为是一个未签名的内容与另一个未签名的内容而生成的。 来源如下: #include #include #include #include int
好吧,这一定很愚蠢。我在移动一些代码时遇到了这个问题,并认为我打错了字或未能正确使用调试器。作为健全性检查,我创建了这个测试用例,但它似乎仍然失败。 unsigned int vtxIdx
我有一个同事不热衷于使用现代 C++ 例如,当我要求他开始使用 r_value 引用时,他不会这样做。当我要求他使用 std::array 而不是 c 数组(char example[8])时,他不会
我有一个无符号字符数组,例如Data[2]。我需要它来与返回 unsigned int 的函数的输出进行比较。 我尝试将 Data[2] 转换为 unsigned int,反之亦然。它没有用。 我想做
我遇到了一个我不太明白的警告。警告是通过将我认为是未签名的与另一个未签名的进行比较而生成的。 这是来源: #include #include #include #include int mai
在下面的程序中,我使用了 unsigned 关键字。 #include int main() { unsigned char i = 'A'; unsigned j
整数值转换为浮点值并再次返回时是否与原始整数值相同? 例如: unsigned x = 42; double y = x; unsigned z = y; 假设编译器没有优化浮点转换,x == z 是
这个问题在这里已经有了答案: Difference between unsigned and unsigned int in C (5 个答案) 关闭 9 年前。 我理解 unsigned 和 un
您好,我遇到了一个关于位运算的小概念问题。请参阅下面的代码,其中我有一个 4 字节的无符号整数。然后我通过将地址分配给无符号字符来访问各个字节。 然后我将最后一个字节的值设置为 1。并对 unsign
我是一名优秀的程序员,十分优秀!