Calling a C++ function from C# by passing a string with variable size to it -


I am calling a string with a C + code and calling from the C # code. The C ++ function is responsible for filling the string material. The following code is:

C #party:

  var abc = new string builder (4096); // will have to change this var result = Basic methods. SignCrcFile (ABC);   

C ++:

  bool __cdecl SignCrcFile (char * abc) {... char * tempStr = "hello all"; // for example // copy it to ABC string strcpy (ABC, tempStr); Back true; }   

The problem is that tempStr's size in the C ++ function is dynamic (the above assignment for TempStr is only an example). In such a case, it is not a hard code that the size of ABC string is in the size of 4096 bytes on the C #. The first solution can be a solution to create 2 functions on the C ++ side to get the size of the string. Then allocate that size using StringBuilder in the C # side then use the next function to bring the entire string from C ++ to the C #. But no suggestion this may not be the most optimal way?

The stringbilder is not fixed on 4096 characters, it initially allows access to 4096 B , But the last size of the string when you do The variable length of toasting 4096 will be variable.

If you fear that this will not be enough then you can increase it.

Otherwise, you can add an integer to the function call * and if you have four * zero, put the required size on that integer, in this way you can call the function once without stringbilders, get the shape It is possible to resume the function with such size and stringbuilder.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -