Wayman
Wayman

Reputation: 73

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)
{
....
}

Upvotes: 7

Views: 4663

Answers (1)

Rost
Rost

Reputation: 9089

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.

Upvotes: 10

Related Questions