Hi,
I am really desperate about this. I am creating a function driver that should communicate with user mode, to enable communication I create a Symbolic link for the driver and try to access it from user mode by calling CreateFile, of some reason CreateFile fails and GetLastError returns 0x00000001 (Incorrect function.)
When using Compuwares ‘Symbolic Link Viewer’ I can see the link ( e.g. “\Device\SETSDriver” ).
Following are code snaps of the link creation code in the driver and the link association code on user-mode:
DriverEntry:
//L"\Device\SETSDriver"
PUNICODE_STRING pDevName = &Names::FullDeviceName;
//L"\DosDevices\SETSDriver"
UNICODE_STRING pLinkName= &Names::DosDeviceName;
status = IoCreateDevice( DriverObject, 0, pDevName, EXEC_GAURD,
FILE_DEVICE_SECURE_OPEN, FALSE, &m_pControlDevice);
if(!NT_SUCCESS(status))
return status;
status = IoCreateSymbolicLink(pLinkName, pDevName);
if (!NT_SUCCESS(status))
{
IoDeleteSymbolicLink(pLinkName);
status = IoCreateSymbolicLink(pLinkName, pDevName);
if(!NT_SUCCESS(status))
goto ErrExit;
}
User mode app:
*pDriver = ::CreateService(m_hSCM, pDriverName, pDriverName, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, pFullDriverPath, NULL, NULL, NULL, NULL, NULL);
if(0 == *pDriver &&
(::GetLastError() == ERROR_SERVICE_EXISTS ||
::GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE) &&
(0 == (*pDriver = ::OpenService(m_hSCM, pDriverName, SERVICE_ALL_ACCESS))))
{
return 0;
}
SERVICE_STATUS serviceStatus = { 0 };
BOOL bResult = ::StartService(*pDriver, 0, NULL);
if(bResult)
bResult = WaitForState(*pDriver, SERVICE_RUNNING, &serviceStatus);
else
bResult = (::GetLastError() == ERROR_SERVICE_ALREADY_RUNNING);
if (!bResult)
return HRESULT_FROM_WIN32(GetLastError());
m_hSymLink = CreateFileW(L”\.\SETSDriver”, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if(INVALID_HANDLE_VALUE == m_hSymLink)
{
m_hSymLink = CreateFileW(L”\.\Global\SETSDriver”, GENERIC_READ |
GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_OVERLAPPED, NULL);
if(INVALID_HANDLE_VALUE == m_hSymLink)
return E_INVALID_HANDLE; // always gets here ( with GetLastError of 1 (Incorrect function)…
}
Thanks in advance,
Nadav.
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com