-1

I'm using an external library (Qpid Proton C++) in my Visual Studio project. The API includes a method like:

container::connect(const std::string &url) {...}

I call it in my code this way:

container.connect("127.0.0.1");

but when debugging, stepping into the library's function, the string gets interpreted in the wrong way, with a size of some millions chars, and unintelligible content.

What could be the cause for this?

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
Miotsu
  • 1,776
  • 18
  • 30
  • 3
    Running optimised code or code without debug symbols, running a debugger that doesn't understand `std::string`, using different c++ runtimes, many other things. Have you tried getting your program to print the string to see if it is actually correct? – Alan Birtles Mar 11 '19 at 09:47
  • Please provide a [mcve] – Thomas Sablik Mar 11 '19 at 10:52

2 Answers2

1

You need to put the breakpoint inside the function and not at the function declaration level, where the variable exists but is not yet initialized.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • That's what I do. The variable is indeed initialized, and has the same address as the string I pass. Running the app gives me an exception "vector too long" after trying to execute that method. – Miotsu Mar 11 '19 at 10:00
  • In that case, there may be another problem with your code, but it cannot be diagnosed witht he elements you gave. – Matthieu Brucher Mar 11 '19 at 10:33
0

Just in case someone runs into a similar problem, as Alan Birtles was mentioning in his comment, one possible cause is having the library and your code using different C++ runtimes, and that turned out to be the case this time.

In general, as stated in this page from Visual C++ documentation,

If you're using CRT (C Runtime) or STL (Standard Template Library) types, don't pass them between binaries (including DLLs) that were compiled by using different versions of the compiler.

which is exactly what was going on.

Miotsu
  • 1,776
  • 18
  • 30