我正在使用ffi和tyed_dataDart 库,并不断遇到这行代码的错误,
Uint8 START_OF_HEADER = 1 as Uint8;
Run Code Online (Sandbox Code Playgroud)
我的错误:
类型“int”不是类型转换中“Uint8”类型的子类型
我在这里做错了什么?另一个奇怪的事情是,我可以使用这些库编写这行代码,并且我的 IDE 将编译并且不会抛出错误,直到您使用该行代码。我正在使用 Intellij 版本 2019.2.4
我是新来的菲。但我成功地将 dart-ffi 与函数调用一起使用。
现在,我想在 dart ffi 中使用 C++ 对象。我不知道这是否可能,但我尝试过这样的。
构造函数调用的原型是:
function_dart = lib
.lookup<NativeFunction<function_native>>("constructor_function")
.asFunction();
Run Code Online (Sandbox Code Playgroud)
但我有 :
Failed to lookup symbol <constructor_function>,我尝试使用构造函数:
constructor_function
class::constructor_function
class::constructor_function(args)
Run Code Online (Sandbox Code Playgroud)
我做到了nm -gDC <lib>,我可以看到构造函数。
帮助 !
编辑1: @Botje,@Richard-Heap
我正在尝试使用 OpenCV 中的 VideoCapture 实例。
我已按照 Botje 的回答中的说明进行操作。
所以我创建了一个库,如下所示:
绑定.hpp:
#ifndef BIND_HPP
# define BIND_HPP
#include <opencv2/videoio.hpp>
extern "C" {
cv::VideoCapture *cvCreateVideoCapture(char *filename, int apiPreference);
}
#endif
Run Code Online (Sandbox Code Playgroud)
绑定.cpp:
#include "bind.hpp"
cv::VideoCapture *createVideoCapture(char *filename, int apiPreference) {
return new cv::VideoCapture(filename, apiPreference);
}
Run Code Online (Sandbox Code Playgroud)
我用来编译的命令:
g++ -c bind.cpp …Run Code Online (Sandbox Code Playgroud) 我在桌面 Windows 上使用sqflite ffi作为我的数据库。我按照示例中的方式设置了所有内容。该应用程序正在调试构建,但如果我在发布模式下运行该应用程序,我会在sqfliteFfiInit(). 我该如何解决这个问题?
Invalid argument(s): Failed to load dynamic library (126)
Run Code Online (Sandbox Code Playgroud)
Future<void> init() async {
try {
sqfliteFfiInit();
} catch (e) {
print(e.toString());
}
_databaseFactory = databaseFactoryFfi;
String path = '${await _databaseFactory.getDatabasesPath()}\\myDB.db';
_db = await _databaseFactory.openDatabase(path);
final List<Map<String, dynamic>> result = await _db.query(
'sqlite_master',
where: 'name = ?',
whereArgs: <String>['MyDB'],
);
if(result.isEmpty){
await _db.execute('''
CREATE TABLE MyDB (
id INTEGER PRIMARY KEY,
name TEXT
)
''');
}
}
Run Code Online (Sandbox Code Playgroud) 我正在用 C++ 开发一个包,用于 Flutter 应用程序(因此在 Dart 中),使用dart::ffi我想知道是否有更好的调试方法(逐步,变量监视,诸如此类的事情) C++ 代码,而不是记录消息。我在 Android Studio 和 VS Code 中都尝试过,但没有成功。
我正在尝试将我的 MIDI 设备连接到 Windows 上运行的 Flutter 应用程序。我正在使用 win32 和 dart ffi。我有以下内容:
final Pointer<HMIDIIN> hMidiDevice = malloc();
Pointer<NativeFunction<MidiInProc>> callbackPointer =
Pointer.fromFunction(midiInCallback);
final result = midiInOpen(
hMidiDevice,
0,
callbackPointer.address,
0,
CALLBACK_FUNCTION,
);
midiInStart(hMidiDevice.value);
Run Code Online (Sandbox Code Playgroud)
midiInOpen将指向函数的指针作为第三个参数。这是我的回调方法:
static void midiInCallback(
int hMidiIn,
int wMsg,
int dwInstance,
int dwParam1,
int dwParam2,
) {
print('Message: $wMsg dwParam1: $dwParam1');
}
Run Code Online (Sandbox Code Playgroud)
它可以编译并与连接的 USB MIDI 设备一起使用。但是,当我按下 MIDI 设备上的某个键时,出现以下错误:
../../third_party/dart/runtime/vm/runtime_entry.cc: 3657: error: Cannot invoke native callback outside an isolate.
pid=11004, thread=21860, isolate_group=(nil)(0000000000000000), isolate=(nil)(0000000000000000)
isolate_instructions=0, vm_instructions=7ffef50837c0
pc 0x00007ffef51a3732 fp 0x00000057468ff990 angle::PlatformMethods::operator=+0x322d8a …Run Code Online (Sandbox Code Playgroud)