I
I
Ilia Zhitenev2016-03-14 16:55:03
C++ / C#
Ilia Zhitenev, 2016-03-14 16:55:03

Char array or string as DLL function argument?

Hello. I am writing a dll to work with a device via a COM port.
Some functions take strings as arguments. The library can connect both to its own programs and to other environments, such as LabVIEW.
Tell me, how best to make them (function arguments) as a char array or as a string? and what are the pros and cons? You can refer to literature. Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Romanovich, 2016-03-14
@MikalaiR

Better char*, because Firstly, this is more universal (you can connect your lib to any language that can use C-libs), and secondly, as mentioned above, the implementation of std::string differs for different compilers.

P
Peter, 2016-03-14
@petermzg

char* - you are passing a pointer to the data itself.
string - you are passing a pointer to a class whose implementation may differ significantly. The same code optimizer can make its own adjustments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question