How to delete the specified V-Serial Port by name dynamically?(Read 10553 times)
Hi,

I am now developing my applications with the V-Serial Port ActiveX OEM version. My system configuration application will create a specified V-Serial port such as “COM20”, as well it may delete one serial port like “COM18”. The expected calling method will the following:

 

CreateVSerialPort( “COM20” )

DeleteVSerialPort( “COM18” )

 

We can use the property GetCountVirtualPort to get the V-Serial Port count, and then use “EnumVirtualPort” to get all the port names. By this way we can get each serial port name, and then the problem is how to delete it? The V-Serial Port API “delete” have no parameters accept!

Please note that our system my create out multiple Virtual Serial Ports, the user may select one item form the list view to delete. I think we should Attach one Serial port with the port name, then delete it by this method “delete”, in this way the specified port will be deleted. Is it right?

At the end of this letter is my source code on create/delete V-Serial Ports, can you give me some effective instructions on this topic?

Thanks & Best Regards!

 

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

int InitVSerialService()

{

   HRESULT dwRetVal;

 

   // The Class Factory

   LPCLASSFACTORY2 pClassFactory;

   

   // Initialize the COM

   CoInitialize( NULL );

   

   // Initialize the ATL COM

   _Module.Init( NULL, GetModuleHandle( NULL ) );

 

   // The driver object

   CComObject<CDriver> * pDriver;

 

   // Get the class factory

   dwRetVal = CoGetClassObject(

      CLSID_VSPortAx,

      CLSCTX_INPROC_SERVER,

      NULL,

      IID_IClassFactory2,

      ( LPVOID * )( &pClassFactory ) );

 

   // Make sure the driver installed

   if ( FAILED( dwRetVal ) )

   {

      return 0X00;

   }

 

   CComBSTR bstr = L"Copyright (c) ELTIMA Software";   

 

   // Create the instance of this driver

   dwRetVal = pClassFactory->CreateInstanceLic(

      NULL,

      NULL,

      IID_IVSPortAx,

      bstr,

      ( void** )&vsp );

 

   // Make sure this driver installed

   if ( FAILED( dwRetVal ) )

   {

      return 0X00;

   }

 

   // Create the driver instance

   CComObject<CDriver>::CreateInstance( &pDriver );

 

   // Setup the connection point

   dwRetVal = AtlAdvise( vsp, pDriver->GetUnknown(), DIID__IVSPortAxEvents, &dwAdvise );

 

   // Make sure the driver instance is OK

   if ( FAILED( dwRetVal ) )

   {

      return 0X00;

   }

 

   return 0X01;

}

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

void StopVSerialService()

{

   // Stop the this the client with the connection point

   AtlUnadvise( vsp, DIID__IVSPortAxEvents, dwAdvise );

 

   // Release the service

   vsp.Release();

 

   // Uninitialize the COM

   CoUninitialize();   

}

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

int CreateVSerialPort( char * pName )

{

   return vsp->CreatePort( _bstr_t( pName ) );   

}

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

int DeleteVSerialPort( char * pName )

{

   BOOL bRetVal;

 

   // Attch this V-Serial Port

   bRetVal = vsp->Attach( _bstr_t( pName ) );

   if ( !bRetVal )

   {

      return 0X00;

   }

   return vsp->Delete();

}

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

DWORD GetVSerialCount()



   return vsp->GetCountVirtualPort();

}

 

// *****************************************************************************

// Design Notes: 

// -----------------------------------------------------------------------------

int GetCOMPortName( DWORD dwPortID, char * pName, DWORD iSize )

{

   // Get the V-Serial Port Name

   BSTR pVSerial = vsp->EnumVirtualPort( dwPortID );

 

   // Validate the size

   if ( iSize <= 0X06 )

   {

      return 0X00;

   }

 

   // Get the COM port name

   strcpy( pName, _bstr_t( pVSerial ) );

   return 0X01;

}



Re: How to delete the specified V-Serial Port by name dynamically? Reply #1 on: August 04, 2008, 09:17:25 AM
I have replied to your e-mail.



 

Sitemap 1 2 3 4 5