Question

I was trying to execute a DLL function that has __stdcall calling convention using QtConcurrent::run(), but I am getting compile errors.

I've reduced the problem to this example code:

__stdcall void dllFunc() {
    qDebug() << "test";
}

void test() {
    QtConcurrent::run(dllFunc);
}

If I remove __stdcall the code compiles and runs fine. Otherwise I get these compile errors:

error: invalid conversion from 'void (*)()' to 'void (*)()'
error:   initializing argument 1 of 'QFuture<T> QtConcurrent::run(T (*)()) [with T = void]'

Why is this happening, and what is the best workaround?

Était-ce utile?

La solution

Well, for a workaround, I ended up using a wrapper function with the same signature but no __stdcall convention:

__stdcall int dllFunc(int param1, void *param2) {
    qDebug() << "test";
    return 0;
}

int dllFuncWrapper(int param1, void *param2) {
    return dllFunc(param1, param2);
}

void test() {
    QtConcurrent::run(dllFuncWrapper);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top