The title summary for data type conversion in the forum VISIOND [original] Keyword type conversion VC summary type conversion Source Conversation of data type conversion in the forum: Vision deng
-------------------------------------------------- ----------------------------- Description: This article is purely a summary of the post related to type conversion,
I have not tested all methods, just to give you a reference.
Reader level: beginner
INT i = 100; long L = 2001; float f = 300.2; Double D = 12345.119; char username [] = "Cheng Peijun"; char TEMP [200]; char * buf; cstring str; _variant_t v1; _bstr_t v2;
First, other data types are converted to strings
Short integer (INT) ITOA (I, TEMP, 10); /// Transforms i into a string into TEMP, the last digit represents decimal ITOA (I, TEMP, 2); // Press binary to convert Long integer (LONG) LTOA (L, Temp, 10); Float, Double) can be converted with FCVT, which is an example in MSDN: int Decimal, Sign; Char * Buffer; Double Source = 3.1415926535; buffer = _FCVT (Source, 7, & Decimal, & Sign); Run Results: Source: 3.1415926535 Buffer: '31415927' DECIMAL: '31415927' DECIMAL: '31415927' DECIMAL: 1 SIGN: 0DECIMAL represents the position of the decimal point, SIGN represents symbol: 0 is positive, 1 is negative number cstring variable Str = "2008 Beijing Olympic Games"; buf = (LPSTR) (LPCTSTR) str; BSTR variable BSTR bstrValue = :: SysAllocString (L "programmer"); char * buf = _com_util :: ConvertBSTRToString (bstrValue); SysFreeString (bstrValue); AfxMessageBox (BUF); delete (buf); ccombstr BSTRVAR ("test"); char * buf = _com_util :: convertBSTRTOSTRING (BSTRVAR.M_STR); AFXMESSAGEBOX (BUF); delete (buf);
_BSTR_T variable _BSTR_T type is packaged for BSTR, because it has been overloaded = operator, so it is easy to use _bstr_t bstrvar ("test"); const char * buf = bstrvar; /// Do not modify the contents of BUF AFXMessageBox (BUF);
General method (for non-COM data type) to complete the conversion with SPRINTF
CHAR BUFFER [200]; CHAR C = '1'; INT I = 35; long j = 1000; float f = 1.7320534F; Sprintf (buffer, "% c", c); sprintf (buffer, "% d", I); Sprintf (buffer, "% d", j); sprintf (buffer, "% f", f);
Second, the string is converted to other data type STRCPY (TEMP, "123");
Short integer (int) i = ATOI (TEMP); long integer (long) L = atol (TEMP); dounce) D = ATOF (TEMP); cstring variable cstring name = Temp; BSTR variable BSTR BSTRVALUE = :: SysallocString (L "programmer"); ... // Complete using sysfreestring (BStrValue); CCOMBSTR variable CCOMBSTR type variable can directly assign CCOMBSTR BSTRVAR1 ("Test"); ccombstr BStrvar2 (TEMP);
_BSTR_T variable _BSTR_T type variable can be directly assigned _BSTR_T BSTRVAR1 ("Test"); _BSTR_T BSTRVAR2 (TEMP);
Third, other data types are converted to CString using the member function Format using the CString, for example:
Integer (int) str.format ("% d", i); floating point number (FLOAT) Str.Format ("% f", i); string pointer (char *), etc. has been supported by the CString constructor You can directly assign Str = username; for the data type not supported by Format, you can transfer to Char * through the method described above with respect to other data types to the char *, and then assign the value to the CString variable.
Fourth, BSTR, _BSTR_T and CCOMBSTR
CCOMBSTR is the package of ATL to BSTR, _BSTR_T is C to BSTR package, BSTR is a 32-bit pointer, but does not directly point to buffers of strings. CHAR * Convert to BSTR can be like this: BSTR B = _COM_UTIL :: ConvertStringTOBSTR ("Data"); /// Use Nea Before Using Comutil.h and Comsupp.libsysFreString (BSTRVALUE); vice versa Can use char * p = _com_util :: ConvertBSTRTSTRING (B); DELETE P; specifically refer to the specific description of the second paragraph.
CCOMBSTR is overloaded with _BSTR_t, which can be done directly =,! =, ==, etc., so it is very convenient to use. Especially _bstr_t, it is recommended to use it.
Five, Variant, _variant_t and Colevariant
Variant's structure can refer to the definition of struct tagvariant in the header file VC98 / include / OAIDL.H. For the assignment of the variant variable: first assign a value to the VT member, specify the data type, and then assign a value of the same data type in the federation, take an example: Variant Va; int a = 2001; va.vt = vt_i4; // indicate Integer data va.lval = a; // / assignment
For Variant that doesn't assign values, it is best to use Void Variantinit (Variantarg Far * Pvarg); in initialization, the essence is set to vt_empty, the following table, the following table, the following table, the following table, the corresponding relationship of VT and common data:
Byte bval; // vt_ui1. Short iv; // vt_i4. Float fltval; // vt_r4. Double dblval; // vt_r8. Variant_bool boolval; // vt_bool. Scode scode; // vt_error. Cyode scode; // vt_error. CY cyVal; // VT_CY DATE date; // VT_DATE BSTR bstrVal; // VT_BSTR DECIMAL FAR * pdecVal // VT_BYREF | VT_DECIMAL IUnknown FAR * punkVal;.... // VT_UNKNOWN IDispatch FAR * pdispVal; // VT_DISPATCH SAFEARRAY FAR.. * parray; // vt_Array | *. byte far * pbval; // vt_byref | vt_ui1. Short far * pival; // vt_byref | vt_i2. long * plval; // vt_byref | vt_i4. float far * pfltval; // vt_byref . | VT_R4 double FAR * pdblVal;. // VT_BYREF | VT_R8 VARIANT_BOOL FAR * pboolVal;. // VT_BYREF | VT_BOOL SCODE FAR * pscode;. // VT_BYREF | VT_ERROR CY FAR * pcyVal;. // VT_BYREF | VT_CY DATE FAR * pdate; // VT_BYREF | VT_DATE BSTR FAR * pbstrVal; // VT_BYREF | VT_BSTR IUnknown FAR * FAR * ppunkVal;.. // VT_BYREF | VT_UNKNOWN IDispatch FAR * FAR * ppdispVal;. // VT_BYREF | VT_DISPATCH SAFEARRAY FAR * FAR *. PPARRAY; // vt_Array | *. Variant Far * pvarval; // vt_byref | vt_variant. Void far * byref; // generic Byref. CHAR CVAL; // vt_i1. Unsigned short uiVal; // vt_ui2. Unsigned long; int; // vt_ui4. Int intVal; // vt_int. Unsigned int uintval; // vt_uint. Char far * pcval; // vt_byref | vt_i1. UNSIGNED SHORT FAR * PUIVAL; // vt_byref | vt_ui2. Unsigned long far * pulval; // vt_byref | vt_ui4. Int far * pintval; // vt_byref | vt_int. Unsigned int far * puintval; //vt_byref|vt_uint._variant_t is a Variant's package class, which can be used to convert these data types using forced type conversion. To use #include
Colevariant's use is basically the same as _variant_t, please refer to the following example: ColeVariant V3 = "String", V4 = (long) 1999; CString Str = (BSTR) v3.pbstrval; long; long i = v4.lval; six, Other COM data types
CLSIDHRESULT CLSID, LPCLSID PCLSID; CLSID CLSID (L "Mapi.Folder", & clsid; CLSID CLSID; CLSIDFROGID; CLSIDFROGID;
The CLSID obtained ProgIDWINOLEAPI ProgIDFromCLSID (REFCLSID clsid, LPOLESTR * lplpszProgID); for example, we have defined CLSID_IApplication, the following code obtained ProgIDLPOLESTR pProgID = 0; ProgIDFromCLSID (CLSID_IApplication, & pProgID); ... /// can pProgID CoTaskMemFree (pProgID) ; // Don't forget to release
7. ANSI and UnicodeUnicode are called a wide character string, and the use of Unicode strings in COM.
Convert ANSI to Unicode (1) to achieve this macro, for example: CLSIDFROMPROGID (L "mapi.folder", & clsid); (2) Implement conversion through the multibytetowideChar function, for example: char * szprogid = "mapi.folder"; WCHAR szWideProgID [128]; CLSID clsid; long lLen = MultiByteToWideChar (CP_ACP, 0, szProgID, strlen (szProgID), szWideProgID, sizeof (szWideProgID)); szWideProgID [lLen] = '/ 0'; (3) through A2W macro implemented, for example: USES_CONVERSION; CLSIDFromProgID (A2W (szProgID), & clsid); converting Unicode to ANSI (1) using the WideCharToMultiByte, for example: Suppose // have a Unicode string wszSomeString ... char szANSIString [MAX_PATH]; WideCharToMultiByte ( CP_ACP, WC_compositeCheck, WSZSomString, -1, Szanstring, SizeOf (SzanSIString), NULL, NULL), (2) Using W2A macro to implement, for example: uses_conversion; ptemp = W2A (wszsomeString); eight, other
In the processing of messages, we often need to decompose 32-bit data (DWORD) such as WPARAM or LPARAM to two 16-bit data (Word), for example: lparam lparam; Word Lovalue = Loword (LPARAM); /// Take 16 Word HiValue = HiWord (LPARAM); /// Take 16
For 16-bit data (Word), we can decompose to two 8-bit data (byte) with the same method, for example: Word Wvalue; Byte Lovalue = LobyTe (WVALUE); /// Take low 8 bYte HiValue = Hibyte (wvalue); /// take 8 digits
Two 16-bit data (Word) synthesis 32-bit data (DWORD, LRESULT, LPARAM, or WPARAM) long makelong (Word Wlow, Word WLOW, Word Wlow, Word Wire); LParam MakelParam (Word Wlow, Word Word Word ); LRESULT MAKELRESULT (Word Wlow, Word WHigh); Two 8-bit data (Byte) synthesized 16-bit data (Byte Blow, Byte Bhigh);
From R (RED), G (Green), B (Blue) three colors Get colorref RGB (byte Byred, Byte Bygreen, Byte Byblue), Byte Byblue,, for example, ColorRef Bkcolor = RGB (0x22, 0x98, 0x34);
From the color type color value to RGB three color values Byte Red = getRvalue (BKCOLOR); // get red color Byte green = getGvalue (bkcolor); // get green color Byte blue = getBvalue (bkcolor); // / Get the blue color
Nine, precautions If you need to use the ConvertBSTRTRING such function, you need to add the header file comutil.h, and add comsupp.lib in Setting, or directly below #Pragma Comment (lib, "comsupp.lib")
Postscript: This article is in a hurry, and the mistakes are inevitable, welcome to correct.
Questions when converting BSTR type data to cString type data? When I convert BSTR type data into cstring or "char * type" data, I found no problem in the case where the BSTR type string is shorter, when a longer There will be memory read and write. (Testing under NT, 2000 is this.) According to what you said: 1) String pointer (char *), etc., the data type that has been supported by the CString constructor can be directly assigned STR = UserName; 2) When B is BSTR CHAR * P = _COM_UTIL :: ConvertBSTRTSTRING (B) can be used when type: CSTRING CSTR; BSTR BSTR; .... cstr = com_util :: ConvertBSTRTSTRING (BSTR); ... but BSTR is very large When it is true, it will appear in memory, and I don't know what to do. Also I found CSTR = COM_UTIL :: ConvertBSTRTSTRING (BSTR); it can be simplified to cstr = BSTR; but this problem also appears when BSTR is large. Ask the brothers to help! anxious. Thank you!
How to transform ((List *) fileip.bian -> liang
About LPCTSTR CString to the question of: jakiesun Issue Date: 2001-9-5 20:08:48 I remember before I wrote this piece of code void function () {CString str, str1, str2; function ((char *) (LPCTSTR) STR1); str = str1; ... // debug road This discovery STR2 value changes with the STR change, please explain why, if you have an answer, please inform Wangshaohong@sohu.com, TX first
}
Add lib support of: sharpening Issue Date: 2001-9-10 11:32:12 If you do not add it produces an error in the setting or adding comsupp.lib direct #pragma comment (lib, "comsupp.lib") Microsoft It is considered that the default settings Call Convertion will also appear the same error if it is not set to __cdecl. 1. INT is converted to cstring? ?
Reply: caigzhi (caigzhi) (2001-10-17 11:27:35) Get 0 points CString member function Format ()
INT A = 2131; CString Str; str.format ("% d", a);
Reply to: Tenchi (C ) (2001-10-17 11:32:12) 0 points I = 2001; char STR [10]; _ ITOA (I, STR, 10); cstring szstring = STR ; Reply: Fiolin (in a deep water) (2001-10-17 11:45:40) 0 points can you! !
Reply to: SOHU9CBSVC (Thanks) (2001-10-17 13:24:17) 0 points How to turn Double to CString Reply to: yihuGang (small tiger) (2001-10-17 13:29:15) 6 points INT i = 2131; char * c = new char [20]; cstring str; sprintf (c, '% d', i); str = * C;
Reply to: GU_C_H (GU) (2001-10-17 14:07:17) 0 division _GCVT below is an example of MSDN
EXAMPLE
/ * _Gcvt.c: this program controls -3.1415e5 * to its string representation. * /
#include
Void main (void) {char buffer [50]; double source = -3.1415E5; _GCVT (Source, 7, Buffer); Printf ("Source:% F Buffer: '% S' / N", Source, BUFFER; _GCVT (Source, 7, Buffer; Printf ("Source:% e Buffer: '% s' / n", source, buffer;
OUTPUT
Source: -314150.000000 Buffer: '-314150.'Source: -3.141500e 005 BUFFER:' -314150. '
Reply to: Gu_C_H (GU) (2001-10-17 14:49:56) 6 points INT A = -3.1415E5; CString Str; str.format ("% f", a); Reply to: ruixp Sword) (2001-10-17 15:06:48) 6 points CString member function format () int a = 2131; cstring str ;format ("% d", a);
2. How can the base class be converted to derived objects? int CDaoListView :: OnCreate (LPCREATESTRUCT lpCreateStruct) {lpCreateStruct-> style | = LVS_REPORT | LVS_EDITLABELS; if (CListView :: OnCreate (lpCreateStruct) == -1) return -1; create ImageList; CDaoViewApp * pApp = (CDaoViewApp *) AfxGetApp ();
m_pimagelist (); assert (m_pimagelist! = null); m_pimagelist-> create (16, 16, true, 4, 4); m_pimagelist-> add (PAPP-> Loadicon (Idi_Key)); m_pimagelist-> add ( PAPP-> Loadicon (IDi_ICON4)); m_pimagelist-> add (PAPP-> Loadicon (IDi_ICON5));
ClistCtrlex & CTLLIST = (ClistCtrlex &) getListCtrl (); // I don't understand this sentence, ClistCtrlex looks at the following statement. CTLList.setimagelist (m_pimagelist, lvsil_small); return 0;}
Class ClistCtrlex: Public ClistCtrl // Class CListCtrlex definition. {.....} Class CDAOLISTVIEW: PUBLIC ClistView // CDAOLISTVIEW definition! {...} Note: My problem is getListCtrl () returned is a reference to a CListCtrl object. How can I convert it into a reference to a derived class object? How to support C type conversion?
Reply Post: LHJ (effort to refuel) (2002-1-29 18:56:06) 0 points CListCtrlex & CTLLST = (CListCtrlex &) getListCtrl (); this is a mandatory type conversion, & reply is a reference, lctlist The value cannot be modified after this assignment.
Reply to: WWWSQ (WWWSQ) (2002-1-29 19:09:22) 0 points suggest you find this C book to see, Although VC is known, it is still important to actually C foundation.
Reply to: xcopy (xcopy) (2002-1-29 19:26:16) Get 0 points with Dynamic_cast () can be securely converted.
3. How to convert between CString and Double? Keep the decimal point after the conversion is required, keep the corrective number? ?
CString :: format (%. XE) X is the precision position
Reply to: Pchaos (Miscellaneous White) (2002-1-28 11:21:46) 0 points CSTRING STR; Double DB; Str = "123.456"; DB = ATOF ((LPCTSTSTSTSTSTST); Reply to: HGW111 Hg) (2002-1-28 11:52:57) 0 points CString -> Double: ATOFDOUBLE -> CSTRING: FORMAT Reply to: Pchaos (Miscellaneous "(2002-1-28 13:46:04) 0 CSTRING STR; DOUBLE DB; STR = "123.456"; DB = ATOF ((LPCTSTSTSTSTSTSTST); DB = 777.999; str.format ("% e", db); 4. Character type is converted into int? ? ATOI (STR)
5. _BSTR_T to Unsigned Int? ? _BSTR_T STR; UNSIGNED INT Length = 6; Length = Length-str.length ();
6. VARIANT type conversion problem? I am using the setoutput () function when using MSCOMM, how does the VARIANT variable convert other data types to a Variant type? Such as: cstring-> variant, * char-> Variant, I am not very familiar with the type of Variant, please talk more (preferably an example), thank you!
Reply to post: Reply to: vc_xiaoxin (small new) (2001-12-26 15:43:57) 0 points Variant itself is a complex structure, how do you turn any other data? Referring to reply: MPG_liu (Star) (2001-12-27 18:33:50) After 10 points defined a variant variable, he should be a structural variable, one of which is a character, giving this member. Assignment replies: llnju (llnju) (2001-12-27 18:36:10) Get 0 points really unclear, use _variant_t, Colevariant these Dongdong, very easy to use, replies: Softarts (cdma2000) (2001-12-27 18:41:32) It is 10 points to construct one. Variant varXX; varInt strino; varXX.vt = vt_bs; varXX.Bstrval = stryy.allocsystring (); it should be. Reply to: Softarts (CDMA2000) (2001-12-27 18:42:11) 0 points I also think that Colevariant should use some, huh, I use it. Reply to: bobofu (having a problem questions) (2001-12-27 19:32:18) get 10 points cstring str; _variant_t var; var = _variant_t (str);
7. How does Colevarant convert to CSTRING? CSTRING How to convert to char * cstring how to convert to char [xx]? ?
How to convert to char * wsprintf or = cstring how to convert to char [xx] strung () Reply to: SecretGarden (paradise bird) (2002-1-14 11:55:23) 0 points Colevarant encapsulated Vareant type. The Vareant type is actually a huge union, which naturally has the Unsigned Char * type. CSTRING GetBuffer and Format can achieve the latter two questions 8. v_variant_t type Convert to cString General prompts me CString Uneascent The program is as follows _variant_t vfirstname; // Store data cstring str; // prompts Error vFirstName = PRS-> getCollect (_variant_t ("phone_num"); vfirstname. ChangeType; str = vfirstname.bstrval; // prompt error
Reply Post: Hydnoahark (Noahroom) (2001-11-12 11:56:51) 10 points >> cstring str; // Tips error requires include
To make your project support MFC, follow these steps: 1: Add: #include "afxtempl.h" in your stdafx.h, this is a header file that includes a collection definition of MFC, It has identified the CString class in your project.
2: In your engineering settings, in the General page, select "MFC" as "Using MFC in A Shared DLL"
OK, now compiling your project. Reply to: zhengyun_ustc (^ - ^) (2001-11-12 12:06:56) 5 points _Variant_t BSTRVAL member is a BSTR type. It is a pointer to an OLECHART *. Reply to: Vickowang (Xiaocang) (2001-11-12 12:48:21) 5 points (char *) _ bstr_t (vfirstname) Reply to: Smallfool (SMALLFOOL) (2001-11-12 13:52:54) 4 points may also need a transformation function from Unicode characters to ANSI characters: sun_1112 () (2001-11-12 17:34:44) 0 points Thank you all give me such a big support! :) Reply to: zhengyun_ustc (^ - ^) (2001-11-14 13:07) Get 0 points with Vickowang (Xiao Cang) opinion may have problems, the converted string should be garbled.
Because (char *) conversion requires a constant string resource to force the conversion. So you should: _BSTR_T BSTRTEMP = _BSTR_T (vfirstname.bstrval; tchar sztemp [max_path]; sztemp = (char *) bstrtemp;
9. CHAR * Convert to TCHAR type? ? Direct conversion, TCHAR is equivalent to char * s; tchar * s1 = (tchar *) s; replose: dysxq () (2001-12-21 21:26:25) 0 points to see your program settings ANSI or Unicode, if it is ANSI, directly, if it is unicode, Tchar is equivalent to Wchar, you have to use Mbstowcsz to turn it back: xiaoxiaohan (晓寒) (2001-12-21 23:52:17) 0 points Unicode: wide Byte character set 1. How do I get a character number of characters that contain both single-byte characters and a double-byte character? The run library of Microsoft Visual C can be called to include a function_MBslen to operate multiple bytes (including both single-byte also including double-byte) strings. Call the Strlen function, can't really understand how many characters exactly in the string, can only tell you how many bytes before the end of the end. 2. How do I operate the DBCS (Dual-Dimming Character Set) string? Function Description PTSTR CharNext (LPCTSTR); Returns the address of the next character in the string PTSTR Charprev (LPCTSTSTR, LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTER) BOOL ISDBCSLEADBYTE (BYTE); if this byte is the first of DBCS characters One byte, returns a non-0 value 3. Why use Unicode? (1) Data exchange can be easily exchanged between different languages. (2) Enable you to assign a single binary .exe file or DLL file that supports all languages. (3) Improve the operating efficiency of the application. Windows 2000 is developed using Unicode, if you call any Windows function and send it an ANSI string, then the system first converts the string into Unicode and then passes the Unicode string to the operating system. If you want the function to return an ANSI string, the system will first convert the Unicode string to an ASI string, then return the result to your application. Transformation of these strings requires the time and memory of the system. By developing applications from head to develop applications, you can make your application run more efficiently. Windows CE itself is an operating system using Unicode, which does not support ANSI Windows Functions Windows 98 only supports ANSI, which can only develop applications for ANSI. When Microsoft converts COM from 16-bit Windows into Win32, the company decides that all COM interface methods that require strings can only accept UNICODE strings. 4. How to write a Unicode source code? Microsoft designed WindowsAPI for Unicode so that you can minimize the impact of code. In fact, you can write a single source code file to compile it or not using Unicode. Just define two macros (Unicode and _unicode), you can modify and recompile the source file. The _unicode macro is used for C running files, while Unicode Macro is used for Windows header files. When compiling the source code module, these two macros must usually define. 5. What are the unicode data types defined by Windows? Data Type Description Wchar Unicode Character PWSTR Pointer Pointer PCWSTR points to a constant Unicode string corresponding to the ANSI data type CHAR, LPSTR, and LPCSTR.
The ANSI / Unicode Universal Data Type is TCHAR, PTSTR, LPCTSTR. 6. How do I operate Unicode? Character Set Features Instance ANSI Operation Function Taking the STR Start STRPYUNICODE Operation Function The WCSCPYMBCS Operation Function The _mbs start _MBSCPYANSI / Unicode operation function to start _TCS _TCSCPY (C run library) ANSI / UNICODE operation function with lstrcpy (Windows Functions) All new and unmatched functions have two versions of ANSI and Unicode at the same time in Windows2000. The ANSI version function is ended in A; the Unicode version function ends in W. Windows will define as follows: #ifdef unicode # Define CreateWindowEx CreateWindowewExw # Else # Define CreateWindowEx CreateWindowexa # Endif //! Unicode7. How to represent Unicode string constance? Character set example ANSI "string" unicode L "string" ANSI / Unicode T ("string") or _text ("string") if (Szerror [0] == _Text ('j')) {} 8. Why should Try to use the operating system function? This will help slightly improve the operating performance of the application because the operating system string function is often used by large applications such as the operating system's housing process Explorer.exe. Since these functions are used, they may have been loaded into the RAM when the application is running. Such as: strcat, strchr, strcmp, and strcpy, etc. 9. How to write applications that meet ANSI and Unicode? (1) Several text string as a character array rather than a Chars array or byte array. (2) Use the general data type (such as TCHAR and PTSTR) for text characters and strings. (3) Use the explicit data type (such as byte and pbyte) for bytes, byte pointers, and data caches. (4) Use the TEXT macro for primary characters and strings. (5) Perform a global replacement (for example, with PTSTR replacement PSTR). (6) Modify the string operation problem. For example, functions typically want to pass a cache size in characters, not bytes. This means that SIZEOF (SZBuffer) should not be delivered (SizeOf (SZBuffer) / SizeOf (Tchar). In addition, if you need to assign a memory block for the string, you have the number of characters in the string, then please Living in bytes to allocate memory. This is to say that Malloc (ncharacters * sizeof (tchar)) is called instead of calling malloc (ncharacters) .10. How to make a selection of strings? By calling CompareString the symbol meaning NORM_IGNORECASE ignore the case of letters NORM_IGNOREKANATYPE does not distinguish between hiragana and katakana characters NORM_IGNORENONSPACE not ignore character spacing NORM_IGNORESYMBOLS ignore symbol NORM_IGNOREWIDTH does not distinguish between single-byte character with the same character SORT_STRINGSORT as double-byte characters will be as common punctuation symbols Treatment 11. How to determine whether a text file is ANSI or unicode? Judgment If the two bytes of the text file are 0xFF and 0xfe, then Unicode, otherwise it is ansi.
12. How to determine a string is ANSI or Unicode? Judging with IstextUnicode. IStextunicode uses a series of statistical methods and qualitative methods to guess the cache. Since this is not an exact scientific method, ISTEXTUNICODE may return incorrect results. 13. How to convert a string between Unicode and ANSI? The Windows function multibytetowideChar is used to convert the multi-byte string into a wide string; the function WideChartomultibyte converts the wide string into an equivalent multi-byte string. Reply to: xtky_limi (Pain in your face) (2001-12-22 0:35:58) 0 points above is more than it is. Reply to: xtky_limi (Pain in your heart) (2001-12-22 0:38:13) 0 points Text is a macro phase to l ##
It can be determined as DBMS according to the compilation environment, or a Unicode character set
10. INT type converted to a cstring type? Reply to: tjmxf (End of the World) (2001-12-17 19:59:34) 0 points ITOA () Reply to: zf925 (where there are so many experts) (2001-12-17 20:00:30) 22 points Char M [20]; STR = STR ITOA (I, M, 10); Reply to: Yuezifeng (Wybzd) (2001-12-17 20:00:50) CSTRING STR; Str.Format "% d", i);
Reply to: Kingfish (this flight) (2001-12-17 20:06:27) 0 points Str.Format ("% s% d", str, i); Reply to: tanyajun (disclation) (2001- 12-17 20:09:25) 0 points CString str = "test"; int i = 11; cstring str1; str1.format ("% d", i); str = STR STR1;
Reply to: guanjinke (2-12-17 20:10:42) 0 points I = 11; cstring str = "test"; cstring addition; addition.format ("% d", i) ; Str = addition;
11. Regarding the problem of Sprintf type conversion Sprintf (BUF, "SELECT Price from LS01 WHERE P_DATE> = '%'", t_date) where t_date is a CTIME type, what should be behind? % S is a string type,% C is char, then what is the CTIME type? Reply to: Yakai (Sunset Changhe) (2001-12-17 17:45:47) 0 points Sprintf (BUF, "SELECT price from ls01 where p_date> = '% s'", (lpcstr) t_date.format (" % A,% b% d,% y ")); if not, char TEMP [50]; cstract str = t_date.format ("% a,% b% D,% y "); strcpy (Temp, LPCSTR) STR); Sprintf (BUF, "SELECT Price from LS01 WHERE P_DATE> = '% s'", TEMP); CTIME :: Format Returns CString Reply to: Loh (Le Xiao Tianya) (2001-12-17 17: 52:57) 0 points Waitdon't Know Reply to: Masterz () (2001-12-17 20:21:05) 0 points SQL statement in the date to write a string "YYYYMMDD"
12. Type conversion unsigned int <==> cstring ?? Reply: 8 Posted: 2001-12-17 10:25:23
Unsigned int F; // unsigned int 0 ~ 4294967295cstring g; f = 2300000000; g.format ("% d", f); afxMessageBox (g); error.
Reply to: YDOGG (Gray Rabbit Frequency) (2001-12-17 10:31:29) 0 points Unsigned Int F; // unsigned Int 0 ~ 4294967295cstring g; f = 2300000000; g.Format ("% D" , f); MessageBox (g); // Using AFXMessageBox, you need a window of the window.
Reply to: asdmusic8 (asdmusic8) (2001-12-17 10:35:15) 0 points I AfxMessageBox (g); and MessageBox (g); all good. Wrong is G. From 2300000000 = "1994967296
Reply to: Asdmusic8 (ASDMUSIC8) (2001-12-17 10:36:10) 0 points are 2300000000 = "- 1994967296 Type conversion error.
Reply to: ydogg (Gray Rabbit Frequently) (2001-12-17 10:37:54) 6 points G.Format ("% U", F);
Reply to: asdmusic8 (asdmusic8) (2001-12-17 10:40:24) 0 points to dgsnmpoprate how to get from cstring == >> unsigned int reply person: Kingfish (this flight) (2001-12-17 10: 42:10) Side 6 points are unsigned int, more than 0x7f000000 (2130706432) Of course, can not use% D (Signed int) with% U Replica: Kingfish (this flight) (2001-12-17 10:44:57) 8 points CString == >> Unsigned int CHAR * P = (LPSTR) (LPCSTR) g; f = ATOI (P); 13. Static_cast, Dynamic_CAST and Direct Type Conversion (such as (void *) p)? Posted: 2001-12-14 9:31:13
First copy a small paragraph in MSDN: Class B {...}; Class C: Public B {...}; Class D: Public C {...};
Void f (d * pd) {c * pc = Dynamic_cast
B * PB = Dynamic_Cast (pd); // OK: b IS an Indirect Base Class // Pb Points To B Subobject Of Pd ...} I already know the role of static_cast and dynamic_cast, but there is no MSDN It is mentioned that these two operators are converted with direct type, such as VoID F (D * Pd) {C * PC = (C *) (PD);
B * PB = (b *) (PD); ...} is different. I don't know what I know, thank you, 50 points.
Reply Post: YsDesigned (Qingquan) (2001-12-14 10:03:07) 0 points Static_cast, Dynamic_cast replaces the simplified strong transformation, and eliminates the multi-relay zone. Use these two operational symbols, we can get the type of type information in the log in the log, Dynamic_CAST is used for the conversion of the polymorphic type. Static_cast is used for non-multi-state types.
Reply to: masterz () (2001-12-14 10:05:48) Get 0 points Static_cast <...> compile can find incorrect pointer type conversion Dynamic_Cast <...> Run if it is not correct. The pointer type conversion will return null (void *) forced conversion, if it is incorrect pointer type conversion, there is no way to check, not as good as 2 in 2; Meady () (2001-12-14 11:29:05) 0 classification security replies: Bluecrest (why my VC is still so dish) (2001-12-14 11:45:34) 0 points COM technology insider introduction, I just forgotten it.
14. BYTE Data Type Convert into INT ?? I use BYTE type to read a group of data to do what to turn him into an INT type? If you turn the INT type back to BYTE? How to implement it?
Reply to: LouiFox (Lanling laughing) (2001-12-6 9:18:38) Get 0 points below: Word MakeWord (Byte Blow, Byte Bhigh); Byte Hibyte (Word wvalue); Reply to: Chskim (big knife) (2001-12-6 9:21:04) 0 points INT I; BYTE B; B = 128; i = (int) B;
Reply to: Nannet (like) (2001-12-6 9:38:24) How to use this macro? Is there a simple one, I can now turn Byte into INT, turn back Can you assign a value directly? Reply to: LouiFox (Lanling laughing) (2001-12-6 9:46:24) has 20 points Word Wa; Byte ba = 32, BB = 64; Wa = MakeWord (ba, bb); ... Word Wa = 1234; BYTE BA, BB; BA = Lobyte (WA); BB = Lobyte (WA);
Reply to: Nannet (similar) (2001-12-6 9:54:55) 0 points problem solved, thank you
15. Type conversion problem, unsigned int -> lptstr / lpctstr ?? Published: 2001-8-7 23:49:41 If the conversion is forced, there will be a fatal error, what is good? Can you list some other ways? Thank you prawn!
Reply to: alphaone (always the first fall) (2001-8-8 0:02:43) 5 points you want to convert? If you want to make the value of the int for lptstr / lpctstr, you can use CString: unsigned int a = 100; lpctstr lptext; cstract str; str.format ("% d", a); lptext = (lpctstr) STR ;
Reply to: Tryibest (2001-8-8 8:20:20) 5 points WSPRINTF (Str, "% U", UI); Reply to: zzh () (2001-8-8 9: 04:39) Whether this situation does not require mandatory conversion, it is possible to use WSPrintf directly. Reply to: GJA106 (Chinese characters) (2001-8-8 10:10:51) Get 5 points Unsigned int m_na = 22; LPTSTR LPTSTR; WSPRINTF (LPTSTR, "% U", M_NA);
16. About COM type conversion problem ?? I defined two variables, one is void * piaref = new unsigned char [1000]; the other is m_temp = new ccomvariant (); my question is how to copy the value in PIAREF COPY to M_TEMP in.
Reply to: nichang () (2001-11-21 15:34:04) 0 points CCOMBSTR BSREF = PIAREF; M_TEMP = BSREF.copy () Reply to: VincentChin (2001-11-21 17:04: 24) 0 points CCOMBSTR BSREF = PIAREF; // Error C2440: 'Initializing': Cannot Convert from 'Void *' to 'class atl :: ccombstr'm_temp = BSREF.copy (); // error C2440:' = ' : Cannot Convert from 'CLASIGNED SHORT *' To 'Class ATL :: CComvariant *' Reply to: Nichang () (2001-11-21 17:14:28) Get 0 points to change void * to unsigned char * Reply to: VincentChin (Pen) (2001-11-21 17:22:22) 0 points I use ccombstr BSREF = (unsigned char *) PIAREF, don't you work? Reply to: Vincentchin (Pen) (2001-11-21 17:28:06) 0 branch error: Error Cast ': Cannot Cast' Unsigned Char * 'to' Class Atl :: CCOMBSTR 'Reply to people : Nichang () (2001-11-22 9:12:14) Get 0 points m_temp = :: sysallocstring ((Olechar *) PIAREF) Reply to: VincentChin (2001-11-22 10:43:07) 0 points // error C2440: '=': cannot communication from 'unsigned short *' to 'class atl :: ccomvariant *' Reply to: VincentChin (Pennes) (2001-11-22 11:22:35) 0 M_temp = new ccomvariant (:: sysallocstring (olechar *) PIAREF); there is no error, but my m_temp is a property in the COM component, I want to return the unsigned char type (single byte), but through the above conversion After that, no longer a single byte! How to do? Reply to: JIANGSHENG (2001-11-22 11:36:58) Get 0 points change this attribute type to BSTR Reply to: Graywhite (Gray) (2001-11-22 12:01:09) Get 0 points m_temp = new ccomvariant ((char *) PIAREF); VB is the use of BSTR, who do you want to use? The VC does not have to use Variant. Reply to: graywhite (gray) (2001-11-22 12:18:18) get 19 points, I understand, you want each byte array: SafeArray * PSA = SafeArrayCreateVector (VT_UI1, 0, 1000); if ( ! PSA) _COM_ISSUE_ERROR (ERROR_NOT_ENUGH_MEMORY);
HRESULT HRFOR (LONG I = 0; I <2; I ) {IF (Failed (HR = SafearRayputelement)) _ COM_ISSUE_ERROR (HR);} _ variant_t va; // ketfrude
M_temp = new ccomvariant (va); Reply to: Vincentchin (Pu God) (2001-11-22 14:21:08) 0 points SafearrayPutelement (PSA, & I, PIAREF I) // Error C2036: 'void *': Unknown size replies: Vincentchin (Pennes) (2001-11-22 14:46:05) 0 points to graywhite: Why do I want (long i = 0; i <2; i )? Reply: nichang () ( 2001-11-22 15:16:35) Do you want to convert 0 points, is it to convert the value in the array to CCOMVARIANT as a string? Reply to: Vincentchin (Penanti) (2001-11-22 15:28:35) 0 points I want to return the value of PIAREF to other programs. What I am doing is a COM component. Thank you! Reply to: nichang () (2001-11-22 15:34:40) 10 points Unsigned char * s = new unsigned char [1000]; STRCPY ((char *) s, "1234"); // can be used Your own method sets the value of S. BSTR BSTRS; OLES = A2wbstr ((char *) s); // convert char * into BSTR type
CCOMVARIANT COMVT; Comvt = OLES; // Transfers BSTR to CCOMVARIANT, here can also, Comvt = a2wbstr ((char *));
Reply to: Vincentchin (Pen) (2001-11-22 16:54:07) 0 points thank you! But I still have a question, what should I return if there is a '/ 0'? What should I return? Char * encountered '/ 0' will think it is. The complete design is this, I define a void * to get data from an external device, which should be unsigned char, I want to transfer this return as attribute, allowing other applications (such as VB). Reply to: nichang () (2001-11-22 17:18:09) Get 0 points to convert '/ 0' to other such as '/ 1' is OK, replied: jiangsheng (Jiang Wei) (2001-11 -22 18:07:16) Get 0 Dividing strings A number of groups replied: Vincentchin (Pu God) (2001-11-23 15:54:39) 0 points Thank you for your reply! My problem is solved! As follows: SafeArray * PSA = SafeArrayCreateVector (VT_UI1, 0, 1000); if (! PSA) Return S_FALSE; HRESULT HR; For (long i = 0; i <1000; i ) IF (Failed (HR = SafearRayputelement (PSA , & I, (UNSIGNED Char *) PIAREFTEMPLATE) I))) Return S_false; Variant Va; Va.vt = VT_Array | VT_UI1; VA.PARRAY = PSA; ccomvariant * m_temp = new ccomvariant (); m_temp-> copy & va); 17. Type Conversion Static_cast ReinterPrete_cast Difference ?? Static_cast ReinterPrete_cast's difference
Reply to: TAR (GPS) (2001-11-21 10:06:41) 0 points Static_cast will check the conversion type health relevance If there is no painting with compilation error Reinterprete_cast is hard to turn back: Tigerwoods (tao (2001-11-21 12:28:19) Get 0 points can be understood: In multiple inherits, Static_cast can implement the movement of the object pointer, point to the correct parent class object section, and ReinterPrete_cast does not shift? Reply to: liu_feng_fly (I hate the driver, hey, it is for mixed rice) (2001-11-21 12:35:14) 0 points can be used in multiple inherits can be used in Dynamic_CAST
18. How do you get a string in cstring? ? Reply to: nichang () (2001-11-5 17:06:00) 0 points = (LPCTSTR) cstring variable replies: snake1122 (comprehension) (2001-11-5 17:12:16) 0 minutes method Too much: getat, left, mid, right, etc., you will see how you take it! Reply to: DUSB (Porsche) (2001-11-5 17:34:29) 0 points can be Getat, Left, MID, Right return type is CSTRING, still can't be used, I am going to take these strings Weird, there is no String type in the VC. (I want a string is the branch name in the tree control) Reply to: ALPS_LOU (Yunfei) (2001-11-5 17:41:36) 0 points have string type, to include
19. How to convert from the cstring type to a Unicode String type? Reply to: ychaner (anemia) (2001-10-20 10:28:48) 0 points CString itself supports Unicode. As long as you choose Unicode compilation, the generated executor is to support Unicode
Reply to: Ychener (Anemia) (2001-10-20 10:30:04) 0 points CSTRING class is an adaptive like Tchar, if you define Unicode macros, you will compile with Unicode.
Reply to: xjl1980_81 (Along) (2001-10-20 10:35:16) 0 points are not, I have a function in a function of Unicode String type, such as to fill L "ABC", and quotation marks The content is changed, and now I have a TEMP variable, which is the type of cstring. How to use it? Reply to: XT_JAT (Samba) (2001-10-20 10:39:37) 0 points _t () _ text () does not work? Reply to: xjl1980_81 (Aolong) (2001-10-20 10:43:18) 0 points are not replied: jeffery__chen () (2001-10-20 11:04:53) 0 points forced transformation: CString Temp Wchar wtemp = (wchar) Temp; Reply to: xjl1980_81 (Aron) (2001-10-20 11:37:06) 0 points to: jeffery__chen () is wrong, an incorrect replies: hongzhh (关 儿) (2001-10-20 11:39:42) 0 points problem is this: TEMP is a cstring type variable, the value of zhh now has an API Pccert_Context WinApi CertFindCertificateInstore (Hcertstore HcertStore, DWord DWFINDFLAGS, DWORD DWFINDFLAGS, DWORD DWORD DWFINDFLAGS, DWORD DWFINDTYPE, Const void * pvfindpara, // This place uses l "zhh" no problem // How to convert how to use temppccert_context pprevcertContext);
Thank you soon, please help us.
Reply to: hongzhh (关 儿) (2001-10-20 13:27:10) 0 points Wchar wszdomain [256]; MultibyTetowideChar (CP_ACP, 0, Temp, Strlen (Temp) 1, WSzusername, Sizeof (WSzusername) / sizeof (WSZUSERNAME [0]));
WSZUSERNAME is the conversion value
Reply to: Ychaner (Anemia) (2001-10-23 11:43:05) 0 points As long as you use the cstring function, if you want to use a strcpy function, look at the general situation in MSDN A function of responding to Unicode. Just replace _TCSCPY, etc. Reply to: ychaner (anemia) (2001-10-23 11:44:10) 0 points You have defined unicode macro? 20. How to convert the DATE data type read from the database with ATL and does not support the Date data type read from the database back to the string ??
Replica: zhxuys (zhxuys) (2001-9-24 10:36:47) Get 0 points ATL to map the DateTime type column map to the DBTimeStamp type, remove the type of Year, Month, Day, etc., then pass these data Back to the client, constructed replied by ctime: Yuanxu (Asahi) (2001-9-24 11:18:14) 0 points to zhxuys: ctime is the MFC class, which cannot be used when ATL does not support MFC. Date is a Double * Reply to: zhxuys (zhxuys) (2001-9-24 11:57:01) 0 points you are in the client and server only with the data type or variant type specified by ATL, while at the client It can be re-constructed with the MFC to reconstruct the desired data structure 21. Type conversion, CSTRING to WCHAR_T??
CSTRING SS ("AABB"); Wchar_T * CC; cc = ss.allocsystring ();
twenty two. How to convert a CString type to _BSTR_T type? Reply to: wei97081116 (Wei Xiaobao) (2001-9-4 11:19:30) Get 20 points CString B; _BSTR_T A; A = (_ BSTR_T) B;
Reply to: zhaozhen1212 (Zhao Zhen) (2001-9-18 1:30:18) 0 points _BSTR_T a = B.allocsystring () ;;
twenty three. How to convert a cString type into a normal string, such as char *?
Reply to: liu_feng_fly (I hate the driver, hey, it is for mixing rice) (2001-9-17 18:00:52) 0 points, so use it directly, because there is such a conversion in the class Function replies: YDOGG (Gray rabbit frequency) (2001-9-17 18:01:21) 0 points CString Show;
Char * p = show.getbuffer (Show.getLength ()); Reply to: jiangping_zhu (Naocuri's Wind Blade) (2001-9-17 18:02:05) 0 points (char *) (LPCTSTR ) STR replies: BMouse (mouse) (2001-9-18 0:10:56) 0 points agreed upstairs! Reply to: bmouse (mouse) (2001-9-18 0:13:22) 0 points You can also direct CString buffers through getBuff, but you have to releasing the buffer.
twenty four. CSTRING type Convert to unsigned char types? ? Reply to: ljn (*) 风 倜傥 倜傥 倜傥, Yushu is located again (*) (2001-9-17 12:46:01) 0 points can be used by CString.getBuffer function replies: xpmao () (2001 -9-17 13:09:09) 0 points CString strWork; Messagebox (0, (lpstr) strwork, 0, 0); or MessageBox (0, strwork.getbuffer (0), 0, 0);
Reply to: Sandd (2-17 13:17:32) 0 points CString String;
(Lpctstr) String; Reply to: jeff_hunter (Pandalee) (unsigned char *) (LPCTSTR) Reply to: fandh (good) (2001-9-17 14) : 00: 57) Get 0 minutes Replies: YGD (YGD) (2001-9-17 16:11:17) 0 points unsigned char * p; cstring str; int; int Length = str.getlength (); for (int i = 0; i 26. CString ---- char * Defines the variable of char * aa, now there is a CString variable BB, how to assume the value of BB to AA? Reply to: emmai (WATAXIWAWATAXI) (2001-8-10 11:57:33) 0 points aa = bb.getBuffer (); Reply to: hswqs (??????????????? ???) (2001-8-10 11:59:01) 0 points AA = (LPSTR) (LPCTSTSTR) BB; Reply to: YDOGG (Gray Rabbit) (2001-8-10 12:27:23) 0 points 1.aa = bb.getBuffer (bb.getlenth ()); // First method 2.AA = (LPCTSTR) BB; // Second method Reply: zhizhi () (2001 -8-10 13:16:23) 0 points AA = (Char *) (LPCTSTR) BB, HEHE 27. There is a BSTR * type parameter in a COM interface function, you need to convert a char * type to a BSTR * type, don't know how to convert? Since this parameter value needs to be removed after calling this function, it can only be used with a pointer, and what type of data passes parameters should be used when calling? Prawns help. BSTR BSTR = SYSALLOCSTRING (L "string"); this conversion, you use the address operator & ah, you have to have new NEW Reply to: yongyue2000i (Xiao Lu) (2001-9-9 18:38:26) 13 points cstring str = "abcd"; bstr bstr = str.allocsystring (); Reply to: houjzs () (2001-9- 9 19:14:44) Get 13 points BSTR B = SYSALLOCSTRING (Olestr "); 28. Do you want to convert a Double number to the CEDIT control requires type conversion? Reply to: JIANGSHENG (Jiang Wei) (2001-8-24 14:46:17) 0 points Void AFXAPI DDX_Text (CDATAEXChange * PDX, INT NIDC, Double & Value); Reply to: Xiezhsh (Snow Board) (2001-8) -24 14:56:22 0 points If your CEDIT related member variable is Double type, it is not used. (ClassWizard adds a member variable dialog box, Variable Type selection double) Reply to: xiezhsh (Snow Bank) (2001-8-24 14:58:16) 0 points If your CEDIT related member variable is not Double type It is a cstring type, then use LTOA () to convert to a CString type, replied: Haven (2001-8-24 14:58:32) 0 points M_EDit.Fromat ("% L" , Varbouble; Updatedata (false); Reply to: 12345678 () (2001-8-24 14:59:54) 0 points cstring m_edit.format ("% lf", doublevar); getdlgitem (editid) -> setWindowText (m_stredit); 29. How to convert WindowPlacement * to a char ** type ?? (char **) & PWP 30. How to convert CSTRING types into char *? Reply to: DCZ (DCZ) (2001-8-19 19:13:27) 5 points // Str Is CString varchar * temp = strDUp (STR); ... free (temp); Reply to: yu900 (blast Wolf) (2001-8-19 19:57:25) 0 points getBuffer (); you can! Reply to: aileen_long (Challenge 2001) (2001-8-19 21:10:35) 0 points agreed upstairs! Reply to: CZH912 () (2001-8-19 21:27:08) 0 points CHAR BUF [20]; Printf (BUF, "% s", string); Reply to: CasL (CASL) (2001-8-19 22:59:44) 5 points CString S ("ABC"); char * TEMP = S.GetBuffer (10); ... s.releasebuffer (); Reply to: Cocia (Gaoya) (2001-8-19 23:04:23) 0 points Char * Temp = S.GetBuffer (10); 10 What do you mean? Reply to: kevin_dong (Dream Cactus) (2001- 8-20 10:26:35) 0 points // Str is cstring varchar * temp = strdup (str); // freefree (temp); I can compile in a program, but in another There is always an error in Cannot CONVERT Parameter 1 from 'CString' to 'Const Char *'. STR and TEMP types are the same. Why is that? Reply to: DCZ (DCZ) (2001-8-20 14:13:45) 0 points You May Setting your compiler Option to Unicode, in this case, declare the var: // Str is cstring var_tchar * temp = _tcsdup (str); // Freefree (STR); 31. SA, SB is two structural types ?? sa * a; sb * b; (sb *) a-> ... (call function) Is this time a type, pointing to SA or SB, the compiler is generated Is a temporary pointer? In addition, b = (sb *) a; what type is A.. ? ? Reply Post: Reply: Ddeng (Deng Deng) (2001-8-9 17:13:58) The type of 0 points A always is the type of SA * B is always SB * When the mandatory type conversion is Temporary pointer replies: Gold_water (no resistance) (2001-8-9 17:30:46) 0 points agreed upstairs. 32. CHAR BUFF [100], char username [50] [100], how to pass the value of buff to username, is it a user in the username array? ? // 0 =
Reply to: Kekeke (I am going to learn from you) (2001-7-26 10:24:22) 0 points, what is it? Assign a certain item in the username to BUFF? how to do? Reply to: Benbensan (Stupid 3) (2001-7-26 10:26:53) 0 points // 0 =
Reply to: JFZSL (commander commander) (2001-7-26 10:32:57) 0 points to take a good look at the book of the old man! OK? Reply to: Kekeke (I am going to you) (2001-7-26 10:44:25) 0 points. . . . ! 33. How do I convert the SystemTime type to Time_t type? SystemTime St; GetLocalTime (& St); CTIMETM (St.wyear, St.wmonth, St.wday, St.WHOUR, ST.WMINUTE, St.WSecond); TIME_T T = TM .Gettime (); 34. Unsigned char exponent [10]; // Eunsigned long ebytes; // e The number of bytes is converted into DWORD type!?? Use forced type conversion (DWORD) ebeytes; (dword) exponent [i]; // (0 <= i <= 10); Reply to: xjl1980_81 (Aolong) (2001-7-26 16:47:29) 0 points I said to convert E to DWORD type is to say to convert the contents in Exponent into DWORD type Reply to: Cloudshadow1 (Yun Shadow) (2001-7-26 17:13:30) Get 0 Distribution Mandatory Type Conversion, (DWORD High 24-Bit Automatic Add 0) DWORD DES [10] for (INT I = 0; I <11; i ) des [i] = exponent [i]; as for that ULONG is also used in a mandatory type soft change. 35. How do I convert the TIME_T type to the SystemTIME type? Reply to: Haven (Daidian) (2001-7-26 17:12:36) 0 points Typedef struct _systemTimeTypedef long time_t is obvious! Reply: Facexy (Facer) (2001-7-26 17:17:38) 0 points oh, asked, the opposite of the front and rear; Further, TO upstairs: conversion is possible struct tm * tblock; SYSTEMTIME SystemTime; memset (& SystemTime, 0, sizeof (SYSTEMTIME)); tblock = localtime (& timer); SystemTime.wYear = tblock-> tm_year 1900; SystemTime .wMonth = tblock-> tm_mon 1; SystemTime.wDay = tblock-> tm_mday; SystemTime.wHour = tblock-> tm_hour; SystemTime.wMinute = tblock-> tm_min; SystemTime.wSecond = tblock-> tm_sec; SystemTime.wDayOfWeek = TBLOCK-> TM_WDAY; RETURN & SystemTIME; Reply to: ZJH73 (Big Octopus) (2001-7-26 20:28:28) 0 points have two methods: 1. Construct a CTIME object with a CTIME class with a Time_t type, A SYSTEMTIME structure is defined again, and finally the time to convert the time to the SystemTIME structure with the member function of the CTIME class. 2, use the GMTIME function GMTIME function to convert the TIME_T time to the TM structure and return a TM pointer, and then assign the corresponding item corresponding to the SystemTIME, but use this method to pay attention to these two types. Structure is a bit different from the counting method, one generally starts with 0, one generally starts, assigns the correction when assigning values, and also pays attention to one of the systemTIME structure is milliseconds, and Time_T is Second count. Reply to: zjh73 (big octopus) (2001-7-26 20:32:13) Get 0 points can also use the CTIME class to construct a CTIME object with the SystemTime structure, and the member function in the CTIME class. GetTime returns a corresponding Time_T. 36. I am learning SDK programming now, I encountered the problem is: I define a static long shape variable, static long lscore = 0; I want to change the title of the window to the shaping value, use the setWindowText function, due to its Two parameters require data types to unsigned short *, but always compile errors when enforced conversion: Cannot Convert Parameter 2 from 'unsigned short *' to 'const char *' later changed to LPCTSTR to implement forced conversion There is no compilation error, but the function is always unsuccessful. Ask you how high people, what is going on? ? ? Reply to post: Reply to: prog_st (st) (2001-8-4 21:20:07) 0 points / * itoa.c: this Program Converts Integers of Various * sizes to strings in various radixes. * / #include Void main (void) {char buffer [20]; int i = 3445; long L = -344115L; unsigned long ul = 1234567890ul _ITOA (I, Buffer, 10); Printf ("String of Integer% D (Radix 10):% S / N", I, Buffer; _ ITOA (I, Buffer, 16); Printf ("String of Integer% D (RADIX 16): 0x% S / N ", I, Buffer; _ ITOA (I, Buffer, 2); Printf (" String of Integer% D (RADIX 2):% S / N ", I, Buffer; _LTOA (L, Buffer, 16); Printf ("String of Long Int% LD (Radix 16): 0x% S / N", L, Buffer; _ULTOA (UL, Buffer, 16); Printf ("String of unsigned long% Lu (RADIX 16): 0x% S / N", UL, BUFFER) OUTPUT String of integer 3445 (radix 10): 3445String of integer 3445 (radix 16): 0xd75String of integer 3445 (radix 2): 110101110101String of long int -344115 (radix 16): 0xfffabfcdString of unsigned long 1234567890 (radix 16): 0x499602d2 Reply to: LWG7603 (3rd release personnel) (2001-8-4 21:36:15) 0 points Tchar STR [255] = {_ t ('/ 0')}; _ stprintf (str, _t ("% D "), lscore; setWindowText (hwnd, str); 37. I need a char * type data in the buf that I sent by Socket, I want to convert a Structure into char * sends it. I use struct abcd * abcd; char * buf; abcd = (abcd *) Calloc (1, sizeof (abcd)); buf = (char *) Calloc (1, sizeof (abcd)); // / 给 中 中 中 中There are multiple char [] values and INT values /// Memcpy (BUF, ABCD, SIZEOF (ABCD)); // STRCPY (BUF, (Char *) ABCD); nor SOCK (Host, BUF , ....); // Sock (Host, (char *) BUF, ...); It is not possible to here, this buf is always wrong, everyone knows why no. Reply to: wolf721 () (2001-7-30 18:18:34) Get 5 points you pass is a pointer value, not data replies: kiko_lee (瞧) (2001-7-30 18:50: 49) Get 0 points but use Memcpy this is copying the entire data over the past replies: LZ_0618 (LZ_0618) (2001-7-30 19:26:44) 5 points you use VC ??? change to abcd * ABCD There is no problem after compiling after compilation! Sock (Host, BUF, ....); this is not aware of what, custom functions? Typedef struct _abcd {int id; char name [10]; ....... Abcd * abcd; char * buf; abcd = (abcd *) Calloc (2, sizeof (abcd)); buf = (char *) Calloc (2, sizeof (abcd)); //// 给 中 中 中, Among them, there are multiple char [] values and int CCD [0] .ID = 1; ABCD [1] .ID = 2; /// Memcpy (buf, abcd, 2 * sizeof (abcd)); strcpy BUF, (char *) abcd); // can not be the content in BUF is also correct! ! Reply to: kiko_lee () (2001-7-31 8:57:52) 0 points I am told according to the brothers upstairs, but I still can't do it, I use Memcpy (buf, abcd) SizeOf (abcd)); middle ABCD, I don't know if it is an address problem. Reply to: Supersusheng (小) (2001-7-31 14:30:42) 0 points, your size is much bigger, take a look. Reply to: YDOGG (Gray Rabbit) (2001-7-31 14:41:52) 0 points can only pass stream data, and the structure is not passed. Reply to: IAMNOTMAN (Norgirl) (2001-7-31 14:50:53) Get 5 points I often use ABCD A; // give a value of each domain (must not contain pointer items) char * buff = new char [SIZEOF (ABCD)]; Memcpy (BUFF, & A, SIZEOF (ABCD)); // or * (abcd *) BUFF = A; ................. If buff Number of words, explaining the problem is here. Reply to: zb_china (lasting water car ZB_China Sina) (2001-7-31 15:16:24) 0 points can't understand Replies: Eggplant (Lara) (2001-7-31 15:42:48) It is best to use Memcpy () because the values in the structure may contain zero bytes, so strcpy () may not be correct, if the Struct is transmitted, it is best to align the struct byte alignment to bytes. Reply: lvfengxun (LFX) (2001-7-31 16:06:57) 5 points directly to send the structural pointer as a parameter of Send, but use what is converted? Struct aa {int a; char b [100];}; struct aa aa; aa.a = 11; strcpy (AA.B, "AAA"); Send (HSocket, (Char *) (& AA), Sizeof (aa), 0) ; // OK Reply: MyDewang (MyDewang) (2001-7-31 16:33:21) 0 points are actually a problem of one byte alignment, such as Struct aa {Int a; char b;}; then Sizeof (struct aa) is not equal to 5, but 8, so give this structure to a char *, there will be more zero inside ... Need to solve this problem, you can add / zp1 in Project-> setting-> link-> Project Options In addition, you can refer to the compilation option of MSDN / ZP ..... replies: lz_0618 (lz_0618) (2001-7-31 19:43:54) 0 points is not a problem, I The procedure has been tested. What is wrong with this old brother with my program? Can you tell me clearly? ? ? I have a problem with the Socket to send a structure. It is not a problem, and it is a program communication between VC and Delphi. Of course, it should pay attention to the problem of byte alignment. In the VC program, as long as it is not intentional, the server and The client's compilation environment is different, it is definitely no problem, the most pass a few bits. Reply to: kiko_lee (everywhere) (2001-8-3 11:02:51) 0 points I found a little problem in the middle of char * memcpy to char *, but if you put it in the middle of Char [], you can Do you know why? Reply to: YDOGG (Gray Rabbit) (2001-8-3 11:40:35) 0 points Memcpy does not COPY Last '/ 0' ... Reply: wenjunlin2000 (Microsoft Star) (2001-8-3) 14:32:17) 0 points are you a mistake because char * is the end of 0 ends: MC_MUSIC (Sand) (2001-8-3 15:07:21) 0 points to pay attention to my procedure : struct abcd * abcd; char * buf; abcd = (abcd *) Calloc (1, sizeof (abcd)); // Initialize Abcdbuf = ABCD; / / The direct value of the pointer can reply to: zhangnanonnet (Winsockzhang) 2001-8-3 16:21:03) Get 0 points you try to turn the type to Byte replose: kiko_lee (瞧) (2001-8-7 9:21:08) 0 points no matter, give Divided, everyone has a lot of suggestions. 38. Double Dou = 12.34; How can I get Char * CH = "12.34"; what is the conversion function? Reply to: Wyzegg (Egg) (2001-7-24 21:26:04) 50 points Double Dou = 12.34; char * ch ;CH = Malloc (100); Sprintf (CH, "% 5.2f", Dou) ; Reply to: Wyzegg (Egg) (2001-7-24 21:28:24) 0 points or #include Void main (void) {int Decimal, Sign; Char * Buffer; int precision = 10; double source = 3.1415926535; Buffer = _ecvt (Source, Precision, & Decimal, & Sign); Printf ("Source:% 2.10F Buffer: '% s' Decimal:% D Sign:% D / N", Source, Buffer, Decimal, Sign);} But the first common replies: Matrix_w (Learn a little bit) (2001-7-24 21:32:43) 30 points INT Decimal, Sign; double Dou = 12.34; char * ch = _ecvt (Dou, 4 , & Decimal, & Sign); Reply to: IMHUA (China Brother) (2001-7-24 21:35:02) Get 20 points Double Dou = 12.34; char * STR; GCVT (Dou, 5, Str); // 5 is the length MessageBox (STR) ; Replies: Matrix_w (Learn a little bit) (2001-7-24 21:37:58) 0 points / * _gcvt.c: this program converts -3.1415E5 * to its string representation. * / # Include Void main (void) {char buffer [50]; double source = -3.1415E5; _GCVT (Source, 7, Buffer); Printf ("Source:% F Buffer: '% S' / N", Source, BUFFER; _GCVT (Source, 7, Buffer; Printf ("Source:% e Buffer: '% s' / n", source, buffer; OUTPUT Source: -314150.000000 Buffer: '-314150.'Source: -3.141500e 005 BUFFER:' -314150. ' 39. I called a stored procedure in the ADO, stored in the stored procedure, @USERADD Char (30), @ username char (10), @ userage char (3), now put char * addr, char * name, char * agnge Assign them separately. I did the following definition: _Parameterptr Para1; _variant_t var1, var2, var3; ================================ ============================== Var1.vt = vt_bstr; var1.bstrval = addr; / (Compile error) === ============================================================================================================================================================================================================= ========= Para1 = m_pcommand-> CreateParameter (l "useradd", adbstr, adpaaminput, 30, var1); m_pcommand-> parameters-> append (para1); compile results appear below: Cannot Convert FROM 'char *' to 'unsigned short * Does not know how to choose vt_bstr? Reply to: TAR (GPS) (2001-7-12 18:49:05) Get 15 points Var1.bstrval should point to the wide character string, NEICODE string USE _BSTR_T TO Convert IT_BSTR_T VAR1 (ADDR); Reply to: happyhackwang () (2001-7-12 20:06:48) 5 points CHAR * To convert to BSTR Reply to: WhiteWaterBluesky (Crazy Digital) (2001-7-13 9:35:15) 10 points SDK is such a 1. First turn the char * to WCHAR_T * 2 with MultibyToWideChar. Use sysallocstring to turn wchar_t * to BSTR Reply to: TAR (GPS) (2001-7-13 14:10:01) Get 0 points Faint, I have written the statement _BSTR_T A (AddR); var1.vt = vt_bstr; var1.bstrval = Wchar_t *) a; Reply to: xwchena (the god of west wind) (2001-7-13 15:57:00) 0 points big brother, after I finished the record set, no results returned. My code is such that: m_pRecordset.CreateInstance (__ uuidof (Recordset)); m_pRecordset = m_pCommand-> Execute (NULL, NULL, adCmdStoredProc); if (! M_pRecordset-> adoEOF) {result1 = m_pRecordset-> GetCollect ((long) 0); if (result1.vt! = Null) {result1.changetype (vt_bstr); cstring strresult1 = result1.bstrval; strcpy (resval, strresult1);} When you see M_PCOMMAND-> execute () M_PRecordset The result is returned if the CHAR * type is changed to the INT type. That is why ah? ? ? Reply to: TAR (GPS) (2001-7-13 19:19:51) 0 points Try Advarchar Reply to: xwchena (the god of Western Wind) (2001-7-13 22:54:21) 0 points or not The record set did not return the result. Reply to: SEESI (I don't want to lie to you, I don't know how to be deceived!) (2001-7-14 0:24:36) 40. How to assign BSTR PVAL to: unsigned char * pw; how to assign: unsigned char digest [16] to bstr * Poutval? Uses_conversion; * poutval = sysallocstring (A2W (LPTSTSTSTS DIGEST)); Unsigned char * pw = (unsigned char *) _ com_util :: convertBSTRTRTSTRING (PINVAL); Author blog: http://blog.9cbs.net/visiond/