Stream Interface Device Driver [xxx_Init xxx_Open.....] 
Author Message
 Stream Interface Device Driver [xxx_Init xxx_Open.....]

Dear all,

I would like to ask how to share a common HANDLE/ COM between an Application
and a DLL? I can't pass the HANDLE created in application to DLL.

<<<<<<<<<My application code>>>>>>>>>>>>>>>>
__________________________________________________________

m_hDevice = ActivateDeviceEx(L"Drivers\\RD10H",NULL,0,NULL);
m_hFile = CreateFile(L"RDD0:",
       GENERIC_READ|GENERIC_WRITE,
       FILE_SHARE_READ|FILE_SHARE_WRITE,
       NULL,
       OPEN_EXISTING,
       FILE_ATTRIBUTE_NORMAL,
       NULL);

void CRD10H_DEMODlg::OnSelect()
{
 char inputBuffer[10];
 char outputBuffer[30];
 TCHAR Temp[30];

 inputBuffer[0]='s';
 inputBuffer[1]='\0';

 wsprintf(Temp, L"OnSelect::m_hFile: %d",m_hFile);
 ::MessageBox(NULL,Temp,L"m_hFile",MB_OK);   // m_hFile is equal to
CreateFile's return value

 DeviceIoControl(m_hFile,2,inputBuffer,3,outputBuffer,4,NULL,NULL);

Quote:
}

<<<<<<<<<<<<<<<<My DLL code:>>>>>>>>>>>>>>>>>>>>>>>>>>
___________________________________________________________________
HANDLE RDD_Init(LPCTSTR pContext,LPCVOID lpvBusContext)
{
     TCHAR Temp[30];
     wsprintf(Temp, L"pContext:%s ", pContext);
     ::MessageBox(NULL,Temp,L"OK",MB_OK);
     InitializeCriticalSection (&g_CriticalSection);
     ::MessageBox(NULL,L"IN RDD_Init function!!",L"OK",MB_OK);
     return (HANDLE) 111111;

Quote:
}

HANDLE  RDD_Open(HANDLE hComPort,DWORD AccessCode,DWORD ShareMode){
    TCHAR Temp[50];
    wsprintf(Temp, L" :hComPort %d", hComPort);
    ::MessageBox(NULL,L"IN RDD_Open function!!",L"OK",MB_OK);
    return (HANDLE) hComPort;

Quote:
}

// m_hFile's value != hComPort --> why??
DWORD RDD_IOControl(HANDLE hComPort,DWORD dwCode,PBYTE pBufIn,DWORD
dwLenIn,PBYTE pBufOut,DWORD dwLenOut,PDWORD pdwActualOut){

 TCHAR Temp[100];
 int s=-1, count =0, i=0;
 char data[50], *rec_data;
 rec_data = &data[0];

 __try
 {
 EnterCriticalSection (&g_CriticalSection);
 wsprintf(Temp, L"RDD_IOControl::hComPort: %d",hComPort);
 ::MessageBox(NULL,Temp,L"hComPort",MB_OK);

  switch ( pBufIn[0] ){
  case 's':

   ::MessageBox(NULL,L"pBufIn[0] == 's'",L"OK",MB_OK);
   while (s!=0 && count <2){
    s = _Select(hComPort, rec_data);
    count = count +1;
   }

wsprintf(Temp, L"RDD_IOControl::CASE 'S' hComPort: %d",hComPort);
   ::MessageBox(NULL,Temp,L"hComPort",MB_OK);
    // m_hFile's value != hComPort --> why??

   for (i =0 ; i < 8 && s == 0 ; i ++ )
    pBufOut[i] = data[i];

   wsprintf(Temp, L"s:%d",s);
   ::MessageBox(NULL,Temp,L"s",MB_OK);
  break;
  } // end switch
 }  // try
 __finally
 {
  LeaveCriticalSection (&g_CriticalSection);
 }

 return (DWORD) hComPort;

Quote:
}

_________________________________________________________________________

Thanks in advance!!

Best Regards,
Crystal



Mon, 19 Sep 2005 12:43:42 GMT  
 Stream Interface Device Driver [xxx_Init xxx_Open.....]
Given your code (reduced for clarity):
HANDLE  RDD_Open(HANDLE hComPort,DWORD Access,DWORD ShareMode){
    return (HANDLE) hComPort;

Quote:
}

// [...] Application
m_hDevice = ActivateDeviceEx(L"Drivers\\RD10H",NULL,0,NULL);
m_hFile = CreateFile(L"RDD0:",
       GENERIC_READ|GENERIC_WRITE,
       FILE_SHARE_READ|FILE_SHARE_WRITE,
       NULL,
       OPEN_EXISTING,
       FILE_ATTRIBUTE_NORMAL,
       NULL);

you say
 "m_hFile's value != hComPort --> why??"

Because they refer to completely different things. hComPort is the value
returned from the RDD_Init(), in your case 111111. Note, also, that
m_hDevice won't be 111111as the OS has it's own internal data structure for
the driver one member of which is the handle returned from your init
function (111111). The driver handles have meaning only to the driver and
are not exposed in any way to applications. The OS has it's own structures
for both the Driver handle and the Open Context that it exposes to the user.

--
Steve Maillet (eMVP)
Entelechy Consulting
smaillet_AT_EntelechyConsulting_DOT_com



Mon, 19 Sep 2005 21:59:20 GMT  
 Stream Interface Device Driver [xxx_Init xxx_Open.....]
Then how to pass m_hFile value to DLL, so that I can send and receive
command from the device?

m_hFile  --> com port handler?
hComPort --> only a value created by us?

Thanks a lot for your help!!!!



Quote:
> Given your code (reduced for clarity):
> HANDLE  RDD_Open(HANDLE hComPort,DWORD Access,DWORD ShareMode){
>     return (HANDLE) hComPort;
> }

> // [...] Application
> m_hDevice = ActivateDeviceEx(L"Drivers\\RD10H",NULL,0,NULL);
> m_hFile = CreateFile(L"RDD0:",
>        GENERIC_READ|GENERIC_WRITE,
>        FILE_SHARE_READ|FILE_SHARE_WRITE,
>        NULL,
>        OPEN_EXISTING,
>        FILE_ATTRIBUTE_NORMAL,
>        NULL);

> you say
>  "m_hFile's value != hComPort --> why??"

> Because they refer to completely different things. hComPort is the value
> returned from the RDD_Init(), in your case 111111. Note, also, that
> m_hDevice won't be 111111as the OS has it's own internal data structure
for
> the driver one member of which is the handle returned from your init
> function (111111). The driver handles have meaning only to the driver and
> are not exposed in any way to applications. The OS has it's own structures
> for both the Driver handle and the Open Context that it exposes to the
user.

> --
> Steve Maillet (eMVP)
> Entelechy Consulting
> smaillet_AT_EntelechyConsulting_DOT_com



Tue, 20 Sep 2005 11:16:27 GMT  
 Stream Interface Device Driver [xxx_Init xxx_Open.....]
You don't send it to the driver. It's the applications handle TO the driver.
The OS takes care of extracting the appropriate open context handle to
provide back to the driver as needed.

You can use DeviceIoControl(m_hFile,....) to send IOCTL codes to your driver
and you can call ReadFile, WriteFile and SetFilePointer as well and the OS
translates those in to calls into your driver sort of like this:

DeviceIoControl(HANDLE hFile, [...])
{
    Get OS data structure from handle
    Get a pointer to the DeviceIoControl implementation for this device
handle from OS data structure
    get the Devices open context from the OS structure
    call Driver's DeviceIoControl with the Drivers Open Context
   return

Quote:
}

--
Steve Maillet (eMVP)
Entelechy Consulting
smaillet_AT_EntelechyConsulting_DOT_com


Tue, 20 Sep 2005 12:44:04 GMT  
 Stream Interface Device Driver [xxx_Init xxx_Open.....]
How can I get OS data structure from handle? and get the pointer to the
DeviceIoControl implementation?

Many Thanks!



Quote:
> You don't send it to the driver. It's the applications handle TO the
driver.
> The OS takes care of extracting the appropriate open context handle to
> provide back to the driver as needed.

> You can use DeviceIoControl(m_hFile,....) to send IOCTL codes to your
driver
> and you can call ReadFile, WriteFile and SetFilePointer as well and the OS
> translates those in to calls into your driver sort of like this:

> DeviceIoControl(HANDLE hFile, [...])
> {
>     Get OS data structure from handle
>     Get a pointer to the DeviceIoControl implementation for this device
> handle from OS data structure
>     get the Devices open context from the OS structure
>     call Driver's DeviceIoControl with the Drivers Open Context
>    return
> }

> --
> Steve Maillet (eMVP)
> Entelechy Consulting
> smaillet_AT_EntelechyConsulting_DOT_com



Fri, 23 Sep 2005 10:44:15 GMT  
 Stream Interface Device Driver [xxx_Init xxx_Open.....]
Huh? You don't need either of those things to implement or use a driver.
Perhaps it would best if you explained exactly what it is what you are
trying to do.

--
Steve Maillet (eMVP)
Entelechy Consulting
smaillet_AT_EntelechyConsulting_DOT_com



Fri, 23 Sep 2005 19:52:47 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Stream Interface Drivers

2. Deployment of Stream Interface HID Compatible driver

3. stream interface drivers using EVC

4. stream interface driver question

5. Device Manager doesnt call XXX_Init

6. Serial Device Driver development: the device manager calls xxx_DeInit()

7. Video Streaming Driver on WinCE

8. Installing a device driver

9. Device Drivers

10. device driver

11. Device Driver HELP!

12. Writing device drivers in C (was: Re: COBOL and Perl)

 

 
Powered by phpBB® Forum Software