Home > Software engineering >  How about MFC MScomm control cstrings intercept processing
How about MFC MScomm control cstrings intercept processing

Time:10-01

I use mscomm controls access to the string on the beidou module, but I how also can not intercept need information, please help greatly?
The following code
 
Void Cuse_mscommDlg: : OnCommMscomm1 ()
{

The static unsigned int CNT=0;
The VARIANT variant_inp;
COleSafeArray safearray_inp;
Long len, k;
Byte data [2048]={0};
Cstrings strtemp;
If (m_mscomm get_CommEvent ()==2) {
cnt++;
Variant_inp=m_mscomm. Get_Input ();
Safearray_inp=variant_inp;
Len=safearray_inp. GetOneDimSize ();
For (k=0; KSafearray_inp. GetElement (& amp; K, data + k);
}
//to empty the cache
M_mscomm. Put_OutBufferCount (0);
M_mscomm. Put_InBufferCount (0);
Safearray_inp. The Clear ();
For (k=0; KByte a=* (char *) + k (data);
Strtemp. The Format (_T (" % c "), a);
M_receive +=strtemp;

}
The UpdateData (false);
}
}

M_mscomm is control variable names, m_receive is receiving box variable names, results are as follows:

I suppose it is solved, but is can not get the desired results,
 for (k=0; KByte a=* (char *) + k (data); 
Strtemp. The Format (_T (" % c "), a);
Stringtemp2 +=strtemp;
}
Int leth=stringtemp2. GetLength ();
while(! Strtemp. IsEmpty ()) {
Int inttemp=stringtemp2. Find (' $', stringtemp2. Find (' * ') + 2);

M_receive=stringtemp2. Left (stringtemp2. Find (' * ') + 2);
Stringtemp2. Mid (inttemp + 1, len - inttemp);
}

With stringtemp2 strtemp data, and then to traverse it, matching the corresponding string then intercept down, but after this code runs directly control card dead
Debugging found stringtemp2 didn't get the whole string

Is there any way to intercept the string to want? If we can directly to the data array operation?

CodePudding user response:

Cstrings: : GetBuffer
LPTSTR GetBuffer (int nMinBufLength);
Throw (CMemoryException);

The Return Value

The An LPTSTR pointer to the object 's (null - terminated) character buffer.

The Parameters

NMinBufLength

The minimum size of The character buffer in characters. This value does not include space for a null terminator.

Few

Returns a pointer to the internal character buffer for the cstrings object. The returned LPTSTR is not const and thus allows direct modification of cstrings contents.

If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other cstrings member functions provides.

The address returned by GetBuffer may not be valid after The call to ReleaseBuffer since additional cstrings operations may cause The cstrings buffer to be reallocated. The buffer will not be reallocated if you do not change The length of The cstrings.

The buffer memory will be freed automatically when The cstrings object is destroyed.

Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, clear, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass 1 for the length to ReleaseBuffer and ReleaseBuffer will perform a strlen on the buffer to determine its length.

Example

The following example demonstrates The use of cstrings: : GetBuffer.

//example for cstrings: : GetBuffer
Cstrings s (" abcd ");
# ifdef _DEBUG
AfxDump & lt; # endif
LPTSTR p=s.G etBuffer (10);
Strcpy (p, "Hello");//to directly access cstrings buffer
S.R eleaseBuffer ();
# ifdef _DEBUG
AfxDump & lt; # endif

Cstrings Overview | Class Members | Hierarchy Chart

See Also cstrings: : GetBufferSetLength, cstrings: : ReleaseBuffer

CodePudding user response:

Didn't understand the building Lord what to do, if the string is correct, that want to flat round is not what you have to code to handle?
This format string if the c/c + + a scan using unskilled, suggested by commas into a vector, and then press the subscript is column, estimates that you will be easier

CodePudding user response:

Mainly character array processing, need according to the protocol format, the interception of the corresponding characters, and then the interception, string, etc
  • Related