I’m calling my own C++ DLL from my C++ Rhino plugin. Both are two projects of the same solution. I’m using VS2020 with /std:c++17.
I cannot pass non-primitive types. For example, I can pass a char* correctly but when I try to pass a string I get a NULL string. Analogous for containers and my own classes.
When I call the DLL from a plain C++ test program it works correctly, so I assume it is not a problem of C/C++ linkage.
Is there any limitation or known problem?
Thanks in advance,
What kind of string and how are you passing it from your plug-in to your DLL?
Sample code can be helpful…
Thanks a lot for your reply. I prepared a very simple test case. I’m taking the example plugin created by the wizard and I’m adding a very simple call to a DLL function:
The DLL gets the int, float and char* parameteers but does not receive the std::vector and std::string parameters:
Can you share the header of the function you’re calling from the plug-in?
Can you try passing the vector and the string by reference? You’re currently passing by value, and although that should work it is not necessary.
You should google “C++ pass std::string to DLL”, as there is a lot written about this.
In the case of a string, I would pass a
const char* (or
const wchar_t*) and do the conversion to
std::string on the other side of the interface, within the DLL.
I wanted to avoid the conversions but I see the best way is to use primitive types unless you build your program and your DLL at the same time (tightly coupled).
Passing the vector and the string by reference does not change the behavior. I found a good answer, following Dale’s suggestion, at:
Thanks a lot for your answer,