0

Can someone suggest the use of Callbacks which does not block the CANoe measurement?

So, I have issues when I try to statically link libraries and make CAPL DLL. I contacted VECTOR but there is no support available.

I tried to include the CAPL Dll in the following ways:

  • CAPL Network Node ‘#pragma library("file path")’
  • “File>>Options>>Programing>>CAPL DLL>> Simulation Setup / Test Setup”
  • “File>>Options>>Programing>>CAPL DLL>> Measurement Setup”
  • CAPL Test Module using ‘#pragma library("file path")’

I have built the DLL for 32bit using a Windows 10 64-bit machine, I tried with VS2017 and VS2019.

Using CPP REST static library

I have properly install Casablanca SDK for use in visual studio 2017 as defined here: https://stackoverflow.com/a/44910349/1919873

I have then created a CAPL DLL with Statically linking cpprest140_2_5.lib, there are no compilation errors and the DLL can be used in CAPL. Now when I call functions with GET request in the DLL inside CAPL everything works without any issues. But when I call the function with POST Request mentioned below, as soon I add the JSON data in request, I get this Runtime Kernel error and the error System Distributed simulation environment: The connection is broken! then the simulation is broken and crashed. I am only having a problem when adding Json in the request, if I remove JSONfrom the request, then everything works fine and I get the response 400 Bad requests from the server.

web::json::value rest_method_post(uint32 handle,http_client client, web::json::value json_v)
{
    CaplInstanceData* inst = GetCaplInstanceData(handle);
    inst->DllInfo("DLL: rest_method_post:");
    web::json::value json;
    try
    {
        client
            .request(web::http::methods::POST, U("/"), json_v) // Here adding JSON results in Runtime error
            .then([&](const web::http::http_response& response) {
            inst->DllInfo(const_cast<char*>(utility::conversions::to_utf8string(response.to_string().c_str()).c_str()));
            json = response.extract_json().get();
        }).wait();
    }
    catch (exception& e)
    {
        inst->DllInfo("DLL: post Exception occured!");
        inst->DllInfo((char*)e.what());
    }
    return json;
}

I have created a console application and the same function works fine.

Using lib curl

I tried to link to another library to get the job done! Unfortunately, the same error exists here also!

I have properly install lib curl 7.67.0 for use in visual studio 2017 as defined here: https://stackoverflow.com/a/54680718/1919873

I have then created a CAPL DLL with Statically linking CURL library, there are no compilation errors and the DLL can be used in CAPL. Now when I call other functions in the DLL inside CAPL everything works, I have no issues. But when I call the function mentioned below to use the CURL library, as soon as it reaches curl_global_init() or curl_easy_init(); I get this Runtime Kernel error and the error System Distributed simulation environment: The connection is broken! then the simulation is broken and crashed.

unsigned int CAPLEXPORT far CAPLPASCAL Rest_UsersLogin_new(uint32 handle)
{
    CaplInstanceData* inst = GetCaplInstanceData(handle);
    if (inst == NULL)
    {
        return -1;
    }

    try
    {
        inst->DllInfo("Request POST"); // 

        CURL* curl;
        CURLcode res;

        struct curl_slist* slist1;
        std::string data = "{\"userName\": \"xAS344yn\",\"userPassword\" : \"TjRFWFJQKRUAxyZGQxMjMj\"}";
        curl_global_init(CURL_GLOBAL_DEFAULT); // this step results in Runtime error

        curl = curl_easy_init(); // this step results in Runtime error
        std::string s;
        if (curl)
        {
            slist1 = NULL;
            slist1 = curl_slist_append(slist1, "Content-Type: application/json");

            curl_easy_setopt(curl, CURLOPT_URL, "https://localhost:61000/users/login");

            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); //only for https
            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); //only for https
            curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
            curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.38.0");
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1);
            curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
            curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
            curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
            //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //remove this to disable verbose output


            /* Perform the request, res will get the return code */
            res = curl_easy_perform(curl);

            /* Check for errors */
            if (res != CURLE_OK)
            {
                inst->DllInfo((char*)curl_easy_strerror(res));
            }

            /* cleanup */
            curl_easy_cleanup(curl);
        }
        inst->DllInfo(const_cast<char*>(s.c_str()));
        //inst->DllInfo(const_cast<char*>(utility::conversions::to_utf8string(response.to_string().c_str()).c_str()));
    }
    catch (const std::exception & e)
    {
        inst->DllInfo("DLL: post Exception occured!");
        inst->DllInfo((char*)e.what());
    }
    return 1;
}

I have created a console application and the same function works fine

Om Choudhary
  • 492
  • 1
  • 7
  • 27
  • You could try to debug the crash. Attach Visual Studio‘s debugger to the RuntimeKernel.exe process and provoke the Crash. Observe the stacktrace. Maybe that gives a clue what happens. – MSpiller Oct 31 '19 at 17:02
  • Wait,... How are DLLs statically linked? Shouldn't be `.lib` statically linked and `.dll` is literally "Dynamic-Link Library"? – Midas Mar 18 '20 at 10:41

1 Answers1

0

Please check your functions , I have made a mistake like calling the same function inside that function.

Example :

Void initialization
{
    initialization();
}
inferno
  • 684
  • 6
  • 21
  • Thank you for taking the time to attempt to provide an answer. In this case, though, the question does not seem to be about runtime issues involving recursion but rather about linking/compilation behavior. I think you may have replied to the wrong question. – Tyler Szabo Oct 08 '20 at 17:14