Hi All, I am developing an SMS application using VC++ 2005 on Vista with Unicode character set. Is it possible to find the language (i.e, either Chinese, English, french etc etc) of the incomming string? That is, if I recieve an message in french language, I should be able to recognize the language as French just from the string itself. Are there any API's which will give me that info? Thanks in advance.
Comp_Users
Posts
-
Identify the language of an string. -
Specifying unqiueness of an attribute in xsd.It works.:thumbsup: Thanks a lot Stuart for the solution.
-
Specifying unqiueness of an attribute in xsd.Hi All, I have an simple xml file for which I generated an xsd file using Altova XMLSpy tool. As I wanted the end user who makes the xml entry to enter an unique ID which is an attribute of one of the elements. I modified the generated xsd file to accomodate this rule by including "xs:unique" node and entered valid values(i believe)but to no avail. Below is my xml file.
<?xml version="1.0"?>
<wwdfdb:DDB xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xybec.com/ns/wwdfdb Sample.xsd">
wwdfdb:MyList
<wwdfdb:Num id="3020">
wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
wwdfdb:StatusInUse</wwdfdb:Status>
</wwdfdb:Num>
<wwdfdb:Num id="3021">
wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
wwdfdb:StatusInUse</wwdfdb:Status>
</wwdfdb:Num>
</wwdfdb:MyList>
</wwdfdb:DDB>Below is the xsd file for the xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
<xs:schema xmlns="http://www.xybec.com/ns/wwdfdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xybec.com/ns/wwdfdb">
<xs:element name="Ver">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="1.0.0.1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Status">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="InUse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Num">
xs:complexType
xs:sequence
<xs:element ref="Ver"/>
<xs:element ref="Status"/>
</xs:sequence>
<xs:attribute name="id" use="required">
xs:simpleType
<xs:restriction base="xs:short">
<!--<xs:enumeration value="3020"/>
<xs:enumeration value="3021"/>-->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="MyList">
xs:complexType
xs:sequence
<xs:element ref="Num" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!--added below lines to achieve uniqueness for at -
Different XSD representation of an element.Oh. I see. Thanks for the info.
-
Different XSD representation of an element.Hi All, I used an Altova XMLSpy tool generate an XSD file for my XML file. The xsd equivalent for an simple xml element "Mfg" generated via the tool was
<xs:element name="Mfg">
xs:simpleType
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>I found out that modifying the above xsd to the one below just works fine.
<xs:element name="Mfg" type="xs:string"/>
Just wanted to know if these 2 XSD representations for the xml element are the same or are they different. Do the elements xs:simpleType, xs:restriction above have any signifance int he above mentioned scenario? (Actually tried going through MSDN but conldn't infer much info). It would be of great help if somebody points out the differences between the 2 if any and brief on it's significance.
-
String manipulation.Thanks for the Info. Yes. You can use _wsplitpath to split the file path into Drive letters, directory, filename, and file extension and now you can do any manipulation with any of the individual members like appending the file name with an string. Now you can put individual file info togather using the api _makepath.
-
String manipulation.Hi Guys, I want to write an function which will accept an file name(along with complete path), append an prefix to it (say Admin to the file name from c:\Sample\sam.txt to c:\Sample\Adminsam.txt). I have written an function via character array manipulation and given below.
#define ADMIN_PREFIX _T("Admin") static void RenameToAdminFile(LPCTSTR szFilePath/*in*/, LPTSTR szAdminFilePath/*out*/) { TCHAR szTempFilePath[MAX_PATH] = _T(""), *pCh; TCHAR szFileName[MAX_PATH] = _T(""); _tcscpy(szTempFilePath, szFilePath); bool bValidPath = false; if (pCh = _tcsrchr( szTempFilePath, _T('\\'))) { pCh++; // Keep trailing "\\" _tcscpy(szFileName, pCh); *pCh = _T('\0'); bValidPath = true; } else { if (pCh = _tcsrchr( szTempFilePath, _T(':'))) { pCh++; // Keep trailing ":" _tcscpy(szFileName, pCh); *pCh = _T('\0'); _tcscat(szTempFilePath, _T("\\")); bValidPath = true; } else { *szTempFilePath=_T('\0'); } } if(bValidPath) { TCHAR szTempAdminFileName[MAX_PATH] = ADMIN_PREFIX; _tcscat(szTempAdminFileName, szFileName); _tcscat(szTempFilePath, szTempAdminFileName); } _tcscpy(szAdminFilePath, szTempFilePath); return; }
Are there any STL API's (Not CString methods)that I could use to achieve the same? An code snippet will be of great help. -
Reading strings containing escape sequence.Hi, In my application, I need to read an unicode string _T("AT+COPS=?\r") from an xml file. The problem I am facing is that when I read an string from the xml file, it is treating the elements "\r" in "AT+COPS=?\r" as 2 different characters rather than a single carriage return value. How do I get around this problem.
-
Access non-exposed port.Found the problem. I was specifying Port Name as _T("COM6:") while the correct was is _T("COM6") i.e, without the colon at the end.
-
Access non-exposed port.Hi, I am working on VS 2005 on Vista platform. I have an mobile data card which exposes an Modem Port and this port appears as an device entry under "Modems" in the Device Manager. In addition to this, the device has another port which i figured out by scanning through the registry and this port does not appear in the device manager. This port appears in the list of available ports displayed by HyperTerminal and also in PortMon and I can connect and talk to the device via HyperTerminal. But in my application when I try to do an CreateFile with that port name, the call fails with GetLastError() returning 2.
TCHAR szPortName\[MAX\_PATH\]=\_T(""); \_tcscpy(szPortName, \_T("\\\\\\\\.\\\\")); \_tcscat(szPortName, \_T("COM6:"); //assume the non-exposed port is COM6. HANDLE hDeviceFile = CreateFile(szPortName, GENERIC\_READ | GENERIC\_WRITE, 0, NULL, OPEN\_EXISTING, 0, NULL); DWORD dwReturn = GetLastError();
Is there something wrong in the CreateFile() function call above. Or is it that Vista allows only ports that are expose/displayed in the Device Manager for an Device to be used by an application?
-
Accessing TCHAR[] array from an vector.Got the solution. I should be using to access the TCHAR stored in the vector as given below.
_tcscpy(szResult, vect[1].c_str());
-
Accessing TCHAR[] array from an vector.Hi, In my application, I store an array of TCHAR[MAX_PATH] strings into an vector as indicated by the code snippet below.
//in the .h file
#include <vector>
typedef std::vector<std::basic_string<TCHAR>> StringVector;//In the .cpp file
BOOL CMyApp::AddStringToVector()
{
StringVector vect;vect.push\_back(\_T("One")); vect.push\_back(\_T("two")); vect.push\_back(\_T("three")); //later on try accessing the vector element. TCHAR szResult\[MAX\_PATH\]={0}; \_tcscpy(szResult, vect\[1\]);
}
I am able to add all the string. But accessing the stored string from the vector is the problem. _tcscpy(szResult, vect[1]); gives an compilation error Error 11 error C2664: 'wcscpy' : cannot convert parameter 2 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const wchar_t *' I think this error is caused because the TCHAR that is stored in the vector as std::basic_string<_Elem,_Traits,_Ax> and that the compiler is not able to convert it to an TCHAR[MAX_PATH]. How do I go about accessing the TCHAR elements in the vector? Please help.
-
WM_POWERBROADCAST on Vista.Tried adding the SetThreadExecutionState() funciton in the WM_POWERBROADCAST handling funciton but to no avail.
-
WM_POWERBROADCAST on Vista.I tried calling the SetThreadExecutionState() function in the OnInitDialog() of an sample dialog based applicaiton with various combinations of flags ES_CONTINUOUS ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED, but to no avail. Could you please tell me as to which flag is to be used with SetThreadExecutionState()?
-
WM_POWERBROADCAST on Vista.I am working on Vista with VS 2005. In my application, I am handling the WM_POWERBROADCAST message and in the message handlig function, execution some code which i must execute when the system goes to hibernate or standby(sleep) mode. I find that on Vista, windows doesnot wait for the WM_POWERBROADCAST message handling function to return a value(true or false) before proceeding to entering into sleep mode. On Vista, the system goes to sleep mode even before the WM_POWERBROADCAST message handling function returns a value. And because of this, my application does not have enough time to execute code in the handler function and results in a crash. Should Windows go/not go to hibernate/sleep mode depending on the return value of the WM_POWERBROADCAST handling function?[MSDN Link]
-
An struct declared within another struct.I am not sure if you guys understand the issue that I am facing.
typedef struct
{
int nID;
TCHAR szName[MAX_PATH];
}MyStruct1;//I declare a list of MyStruct1 object with a key of type TCHAR as below.
typedef std::map, MyStruct1> MyStructList;
Another struct which contains the MyStructList list as it's member.
typedef struct
{
int age;
TCHAR Place[MAX_PATH];
MyStructList ObjList;
}MyMainStruct;//This code gives a crash.
void MyApp::UpdateList(MyStructList &ObjList)
{
ObjList.clear();//Even this line crashes.
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
ObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
//fill this list with multiple MyStruct1 object and unique keys.
}//But the given function adds all the structure object with their key without any crash.
void MyApp::UpdateList2()
{
MyStructList localObjList
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
localObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
//fill this list with multiple MyStruct1 object and unique keys.
}Which means that there is nothing wrong with the insert operation that is performed on the localObjList list object which is a local copy. when I create an instance of MyMainStruct object, will the MyStructList member of MyMainStruct also be instantiated. void main() { MyMainStruct MainObj; UpdateList(MainObj.objMyStructList);//This call crashes. }
modified on Friday, February 13, 2009 3:22 AM
-
An struct declared within another struct.I believe, when I create an instance of MyMainStruct object, the memory is not getting allocated to the MyStructList member. Is my understanding right? If so how do i get about it? I dont want to create any object on the heap and store it's pointer in the structure.
-
An struct declared within another struct.Hi, I have an structure declared in the .h file.
typedef struct
{
int nID;
TCHAR szName[MAX_PATH];
}MyStruct1;//I declare a list of MyStruct1 object with a key of type TCHAR as below.
typedef std::map, MyStruct1> MyStructList;Another struct which contains the MyStructList list as it's member.
typedef struct
{
int age;
TCHAR Place[MAX_PATH];
MyStructList ObjList;
}MyMainStruct;In the .cpp file.
void MyApp::main()
{
MyMainStruct objMainStruct;
UpdateList( objMainStruct.ObjList);
}//The list is being updated in this function below.
void MyApp::UpdateList(MyStructList &ObjList)
{
MyStruct1 MyStructObj;
_tcscpy(MyStructObj.szName, _T("ABCDE"));
MyStructObj.nID = 2532;
ObjList.Insert(MyStructList::value_type(_T("First"), MyStructObj)).second;
//fill this list with multiple MyStruct1 object and unique keys.
}I am not able to update the MyStructList list structure in the function below. When I perform an insert on the list or for that matter any operation on the list, my application (VC2005 on vista) crashes. Is it because the way I have declared an List object inside another structure that this is not working? Plesae help me there.
-
TCHAR as Key in a map.It works now. :) Thanks a lot for the code snippet. Thanks to others who have contributed to this thread.:thumbsup:
-
TCHAR as Key in a map.liangyenchyen, I am not able to get you. All i want to achieve is add my user defined structure and associate a key which is an TCHAR array. some thing like objStructMap.insert(MyStructMap::value_type(_T("Unique1"), structobj1)).second; objStructMap.insert(MyStructMap::value_type(_T("Unique2"), structobj2)).second; objStructMap.insert(MyStructMap::value_type(_T("Unique3"), structobj3)).second; and so on. Later I can access a member using the key as follows MyStructMap::iterator iter = objStructMap.find(_T("Unique1")); How do i achieve this?