locked
Bluetooth Printer can't print via Serial Port Profile, getting error 1168 RRS feed

  • Question

  • Situation:
                 I have a bluetooth printer.  After installing SP1 and SP2 on windows vista, I am able to detect this printer using the add printer wizard.  Once I add this printer, it is assigned COM 7 by Vista.  I know that the driver for this printer is installed (however, I'm not entirely sure if the driver is Vista compatible.  I know that it is XP compatible.)  I then try to send a raw data stream to this printer, via COM 7 but receive the error 1168.  It seems like it won't even connect.
                 I experienced the same issue when I used XP.  I circumvented the problem by using socket API.  However, customer requests have since changed. 

    I guess my quandary can be summarized into two questions:
    1.  Why can't I open a virtual com port with the native microsoft bluetooth stack?  Is there a reference document I can read that points out common pitfalls of implementation?

    I have read the article on "Creating a Connection to a Remote Device Using a Virtual COM Port for windows CE 5.0"  but I didn't think it would apply to my case because I am working with Windows Vista.  If my assumption was incorrect, please help set me straight!

    Below is the basic code I'm trying to use to open a virtual com port. 

    CreateFile(
        __in     LPCSTR lpFileName,
        __in     DWORD dwDesiredAccess,
        __in     DWORD dwShareMode,
        __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
        __in     DWORD dwCreationDisposition,
        __in     DWORD dwFlagsAndAttributes,
        __in_opt HANDLE hTemplateFile
        );
    
    #define GetLastError System::Runtime::InteropServices::Marshal::GetLastWin32Error
    
    BOOL CBlueTooth::openPort()
    {
    	int		e;
    	BOOL	bRet = FALSE;
    	HANDLE	m_hComPort;
    
    	do
    	{
    
    		CString PortNameStr(m_Settings.portName);
    
    		if (m_hComPort==INVALID_HANDLE_VALUE)
    		{
    			// THIS IS WHERE THE CODE FAILS...
    			m_hComPort = CreateFile( PortNameStr, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    		}
    
    		if(m_hComPort == INVALID_HANDLE_VALUE)
    		{
    			// After the code fails, this error message is displayed.  The error I get is 1168
    			wsprintf( m_szTMessage,TEXT ("Failed to open Bluetooth port: %s.  Error %d."), PortNameStr, GetLastError());
    			m_pPrintDemoCtrl->SetWindowText( m_szTMessage);
    			Sleep(3000);
    			m_Log.WriteToLogFile( m_szTMessage);
    			return FALSE;	
    		}
    
    		
    	}while(FALSE);
    
    	return bRet;
    }
    





    Thanks for your help!
    Mercy
    Thursday, December 17, 2009 10:08 PM