conversion from lptstr to wstring : I came up with the same issue,in which I got a LPTSTR portname param as input from a function.I have to convert this into wstring,so that I can fetch the Port paramaters. 


below is the code snippet in which am trying to copy lptstr to wstring.

             void C_PORT_MONITOR::SetPrinterComPortParam(LPTSTR	  PortName)
              {
              #ifdef _UNICODE
              std::wstring			l_ComPortName;
              #else
              std::string				l_ComPortName;
              #endif
             DWORD dwSize,le = 0;
	      dwSize = sizeof(COMMCONFIG);
	     LPCOMMCONFIG lpCC = (LPCOMMCONFIG) new BYTE[dwSize];
	     l_ComPortName = PortName;//mPortName;	
            if(l_ComPortName.length() <= 0 )
            return;
	   bool SetFlag = false;
	 //Get COMM port params called to get size of config. block
	  int length = l_ComPortName.length();
	  int iPos = l_ComPortName.find_first_of(':'); 
	  int iChc = length- iPos; //remove the charactrers after :
	  l_ComPortName = l_ComPortName.substr(0, (length- iChc)); //remove the characters from colon  //COM1
	//Get COMM port params with defined size
       BOOL ret = GetDefaultCommConfig(l_ComPortName.c_str(), lpCC, &dwSize);  
	_RPT1(_CRT_WARN, "C_PORT_MONITOR::SetPrinterComPortParam length=%x,iPos=%x,iChc=%x,l_ComPortName=%s",length, iPos, iChc, l_ComPortName);
	if(!ret)
	{
		le = GetLastError();
		_RPT1(_CRT_WARN ,"C_PORT_MONITOR::SetPrinterComPortParam LastError=%x",le);
	}

I need to assign this portname to l_comportname. and I need to create a substring from this l_comportname as COM1 and I have to use this substring in getdafaultcommconfig()

