c# - Pass a buffer of chars from .NET to COM and get it back updated -
I have the following COM method to call from C #, which provides buffer pchText
( The number of characters that have been copied in pcch
: >
HRESULT next ([outside , Long-term * PCC, [out, size_s (* PCC)] Olescher * Pichtext;
How do I define C # signatures for interop?
So far, I tried to do this:
void nex T (ref int PCC, [Marshall AS (unmanaged type. LPWRR, Size Param Index = 0)] SystemText.StringBuilder Pichtext);
It seems to work, but I'm sure There is no effect on SizeParamIndex
on StringBuilder
.
OK, this is definitely a tough task to call the right call. Your announcement is roughly ok, you just [pressseag] and To apply Seshta and return value of int need to create so that you can search for a S_FALSE return value indicates that there is no next element.
The difficulty can be seen how big the stringbilder will be, the original code gets a raw pointer in the GC heap, which indicates the builder buffer, so the accidents are very fatal. You must put the front of the builder on the appropriate capacity and pass the initial pcch argument.
The Marshaller does copy after the SizeParamIndex function returns only a few letters like PPP indicates if it fits in a buffer for some reason Maybe, if you write more than this, then the program will be immediately revoked with the ExhibitionEngine exception, because it shows that GC Heap was damaged.
Be careful that if you estimate in a capacity is very low then you can not find it necessary. You may only get a small string when the function only copies many characters that do not return any error code. The best way to find out that if this is a problem then it is only to test and knowingly going to a small builder. Focus on the value of the return.
Pointing to a quick digit, in the earliest days of comm, the function signature hits on a hack, in fact returns binary data instead of text through Oleshur *. Strong indication that since the issue the string is not guaranteed to be zero-end. This will not come to a good end in .NET, when the string becomes normalized then the data will be corrupted. Your program crashes when the UTF-16 matches one of the recharged characters. If this is the case, then you need less [] than stringbillers.
Comments
Post a Comment