Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does my C++ app call interface of driver?

I have a driver source code, and understand it. I write a app under user mode. I want to call functions of driver. How should I do?

some driver headers code:

...
BYTE ReadRegister(DEVICE_CONTEXT *pDevice, BYTE SlavAddr, BYTE SlavMode, WORD RegAddr, BYTE* pData, BYTE DataCont);

BYTE WriteRegister(DEVICE_CONTEXT *pDevice, BYTE SlavAddr, BYTE SlavMode, WORD RegAddr, BYTE* pData, BYTE DataCont);
...

driver cpp code pieces:

BYTE ReadRegister(DEVICE_CONTEXT *pDevice, BYTE SlavAddr, BYTE SlavMode, WORD RegAddr, BYTE* pData, BYTE DataCont)
{
.....
}

//-----------------------------------------------------------------------------
BYTE WriteRegister(DEVICE_CONTEXT *pDevice, BYTE SlavAddr, BYTE SlavMode, WORD RegAddr, BYTE* pData, BYTE DataCont)
{
....
}
like image 312
Wayman Avatar asked Sep 01 '12 11:09

Wayman


1 Answers

You could not call directly kernel-mode driver API function. You shall use IOCTL API instead.

Usual workflow scenario is like this:

  1. The user-mode application posts an IOCTL request, passing in information about the function to be called, as well as a pointer to its argument stack.
  2. The kernel-mode driver dispatches the request, copies the arguments onto its own stack, calls the function, and passes the results back to the caller in the IOCTL output buffer.
  3. The caller picks up the results of the IOCTL operation and proceeds as it would after a normal DLL function call.
like image 63
Rost Avatar answered Sep 28 '22 09:09

Rost