title: Issues with Statically linked libraries with CAPL Dll,
body: <p>Can someone suggest the use of Callbacks which does not block the CANoe measurement?</p>
  
  <p>So, I have issues when I try to statically link libraries and make CAPL DLL. I contacted VECTOR but there is no support available.</p>
  
  <p>I tried to include the CAPL Dll in the following ways:</p>
  
  <ul>
  <li>CAPL Network Node ‘#pragma library("file path")’</li>
  <li>“File>>Options>>Programing>>CAPL DLL>> Simulation Setup / Test Setup”</li>
  <li>“File>>Options>>Programing>>CAPL DLL>> Measurement Setup”</li>
  <li>CAPL Test Module using ‘#pragma library("file path")’</li>
  </ul>
  
  <p>I have built the DLL for 32bit using a Windows 10 64-bit machine, I tried with VS2017 and VS2019.</p>
  
  <p><strong>Using CPP REST static library</strong></p>
  
  <p>I have properly install Casablanca SDK for use in visual studio 2017 as defined here:
  <a href="https://stackoverflow.com/a/44910349/1919873">https://stackoverflow.com/a/44910349/1919873</a></p>
  
  <p>I have then created a CAPL DLL with Statically linking <code>cpprest140_2_5.lib</code>, there are no compilation errors and the DLL can be used in CAPL. Now when I call functions with <code>GET request</code> in the DLL inside CAPL everything works without any issues. But when I call the function with <code>POST Request</code> mentioned below, as soon I add the <code>JSON</code> data in <code>request</code>, I get this <code>Runtime Kernel error</code> and the error <code>System Distributed simulation environment: The connection is broken!</code> then the simulation is broken and crashed. I am only having a problem when adding <code>Json</code> in the request, if I remove <code>JSON</code>from the request, then everything works fine and I get the response <code>400 Bad requests</code> from the server.</p>
  
  <pre><code>web::json::value rest_method_post(uint32 handle,http_client client, web::json::value json_v)
  {
      CaplInstanceData* inst = GetCaplInstanceData(handle);
      inst-&gt;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([&amp;](const web::http::http_response&amp; response) {
              inst-&gt;DllInfo(const_cast&lt;char*&gt;(utility::conversions::to_utf8string(response.to_string().c_str()).c_str()));
              json = response.extract_json().get();
          }).wait();
      }
      catch (exception&amp; e)
      {
          inst-&gt;DllInfo("DLL: post Exception occured!");
          inst-&gt;DllInfo((char*)e.what());
      }
      return json;
  }
  </code></pre>
  
  <p>I have created a console application and the same function works fine.</p>
  
  <p><strong>Using lib curl</strong> </p>
  
  <p>I tried to link to another library to get the job done! Unfortunately, the same error exists here also!</p>
  
  <p>I have properly install lib curl 7.67.0 for use in visual studio 2017 as defined here:
  <a href="https://stackoverflow.com/a/54680718/1919873">https://stackoverflow.com/a/54680718/1919873</a></p>
  
  <p>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 <code>curl_global_init()</code> or <code>curl_easy_init();</code> I get this <code>Runtime Kernel error</code> and the error <code>System    Distributed simulation environment: The connection is broken!</code> then the simulation is broken and crashed.</p>
  
  <pre><code>unsigned int CAPLEXPORT far CAPLPASCAL Rest_UsersLogin_new(uint32 handle)
  {
      CaplInstanceData* inst = GetCaplInstanceData(handle);
      if (inst == NULL)
      {
          return -1;
      }
  
      try
      {
          inst-&gt;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, &amp;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-&gt;DllInfo((char*)curl_easy_strerror(res));
              }
  
              /* cleanup */
              curl_easy_cleanup(curl);
          }
          inst-&gt;DllInfo(const_cast&lt;char*&gt;(s.c_str()));
          //inst-&gt;DllInfo(const_cast&lt;char*&gt;(utility::conversions::to_utf8string(response.to_string().c_str()).c_str()));
      }
      catch (const std::exception &amp; e)
      {
          inst-&gt;DllInfo("DLL: post Exception occured!");
          inst-&gt;DllInfo((char*)e.what());
      }
      return 1;
  }
  </code></pre>
  
  <p>I have created a console application and the same function works fine</p>