0

I want to write a plain C DLL to connect to a SOAP server to read/write data there. (Needs to be plain C because this DLL will be used in LabView)

I have to use an API, which is written in Qt. This API provides all sorts of methods to establish said connection. So all I got to do is basically translate the APIs functionality into C.

I tried to do this like this:

in the header file

typedef void* plainc_testlistwrapper;
#ifdef __cplusplus
extern "C"{
#endif
__declspec(dllexport) plainc_testlistwrapper testlistwrapper_init(const char* srv);
__declspec(dllexport) void testlistwrapper_destroy(plainc_testlistwrapper tlw);
__declspec(dllexport) const char *testlistwrapper_get_admin(plainc_testlistwrapper self);

#ifdef __cplusplus
}
#endif // EXTERN C

in the cpp file

__declspec(dllexport) plainc_testlistwrapper testlistwrapper_init(const char* srv)
{
    return new TestListWrapper(TestListWrapper::SoapSecure, QString::fromUtf8(srv));
}

__declspec(dllexport) void testlistwrapper_destroy(plainc_testlistwrapper tlw)
{
    TestListWrapper* toDelete = static_cast<TestListWrapper*>(tlw);
    delete toDelete;
}


//This function will give back the servers admin without the need to be logged in.
__declspec(dllexport) const char* testlistwrapper_get_admin(plainc_testlistwrapper self)
{
    TestListWrapper* tmp = static_cast<TestListWrapper*>(self);
    return tmp->serverAdministrator().toStdString().c_str();
}

as seen here: How to call C++ function from C

Problem that made me ask here

Compiling this code into a DLL works just fine (mingw_4.9.2 32bit , Qt 5.6.1) But when I'm trying to use some of the code in another application (Qt console application to be more specific), I just get a black terminal with the _ symbol blinking. When i try to debug the code nothing happens and the debugger just says the application is running.

I hope I didn't forgot to mention anything important.

Thanks in advance for your answers!

Edit:

I included the library as following

INCLUDEPATH += C:/Path/to/Lib/PlainCLib
LIBS += -LC:/Path/to/Lib/PlainCLib/debug -lPlainCLib

In the main.cpp i simply did

#include "plainclib.h"

When I then add any kind of method from the lib, the idle terminal appears. I emphasize any because I added an add-method just to be sure its not the implemented API which looks like this:

__declspec(dllexport) int add(int a, int b){return a+b;}

I called the add method like this:

std::cout << add(5, 7) << std::endl;

Note: The inclusion of the API, which needs to be translated, is correct as I used this API in other projects successfully.

Community
  • 1
  • 1
Kamui
  • 1
  • 2

0 Answers0