locked
deregister COM Port RRS feed

  • Question

  • Hi Friends,

    I am facing an issue with DeregisterDevice() API, I created an application to print from a WM5 device via bluetooth and this interface is implemented using virtual COM port.
    Here is the issue this application run fine if chose COM6, after printing I need to change BT printer, so trying to deregister the previous Bluetooth printer on COM6, most of the time this is failing and I am not able to re use the same port unless until Cold Boot the device.

    PLS suggest if you have any resolution on this issue.
    Thank you
    SJ.

    Sree
    Monday, January 12, 2009 11:59 AM

Answers

  • Hi,
    from my experience failing to deregister device is in many cases caused by the error in the driver itself. Now I test my dll and in the variable result is 1 (true).

     

    handle = RegisterDevice(_T("COM"), 9, _T("\\RStein.TinyGPS.dll"), 0);   
     
     
    result = DeregisterDevice(handle);  
     

    HTH
    Rene Stein
    http://blog.renestein.net

    Monday, January 12, 2009 4:50 PM

All replies

  • Hi,
    from my experience failing to deregister device is in many cases caused by the error in the driver itself. Now I test my dll and in the variable result is 1 (true).

     

    handle = RegisterDevice(_T("COM"), 9, _T("\\RStein.TinyGPS.dll"), 0);   
     
     
    result = DeregisterDevice(handle);  
     

    HTH
    Rene Stein
    http://blog.renestein.net

    Monday, January 12, 2009 4:50 PM
  • Thank you for the response,
    I got a suggestion to save the handle of the registered device in the registry and call the deregister() with the same handle. I want to try the same method also, I ll let you know if this issue get fixed.

    Thanks
    SJ

    Sree
    Thursday, January 22, 2009 3:38 PM
  • Hi!
    For the last three days, I've been trying to connect and disconnect a BlueTooth printer from my program, and now I have the same problem.

    I can connect to the printer using

    	PORTEMUPortParams pp;
    	memset( &pp, 0, sizeof( pp ) );
    
    	pp.device = btaddr;
    	pp.flocal = FALSE;
    	pp.channel = 1;
    	pp.uiportflags = RFCOMM_PORT_FLAGS_AUTHENTICATE | RFCOMM_PORT_FLAGS_REMOTE_DCB;
    	HANDLE hDev = RegisterDevice (	L"COM",
    					3,
    					L"btd.dll",
    					(DWORD)&pp
    	);
    	if (hDev)
    	{
    		m_pDoc->SetPrinter(hDev); //passes the handle to the pseudo-Document, which sets its m_hDev
    }
    Printing works like a charm, and when I execute the following code right before closing the application, I get no errors either:
    // this is called from my pseudo-Document
    if (m_hDev)
    {
    	AfxMessageBox(_T("Deregistering COM3"));
    	if (FALSE == DeregisterDevice(m_hDev))
    		AfxMessageBox(_T("failed..."));
    }
    When I start the program a second time, I get the ERROR_DEVICE_IN_USE (2404) message. I'm using COM3 every time and cold reset lets me connect to the printer one more time.
    Could you please further elaborate on the driver issue?

    I haven't found this btd.dll neither on my harddisk nor on the target device (SC600 PDT/Windows CE 5, probably a custom OEM build, definately without any documentation), so maybe that could be the problem. Then again, why would data transmission work properly without this driver...

    Kind Regards,
    Patrick Marlovics
    Tuesday, August 11, 2009 7:48 AM