在下还是不太明白,我将代码贴出来,请两位指点。
//LEDDRIVER.CPP
#include "stdafx.h"
#include
#include
#pragma comment(lib,"ceddk.lib")
DWORD DEM_Init(LPCTSTR pContext, LPCVOID lpvBusContext);
BOOL DEM_Deinit( DWORD hDeviceContext );
DWORD DEM_Open( DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode );
BOOL DEM_Close( DWORD hOpenContext );
BOOL DEM_IOControl( DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut );
void DEM_PowerUp( DWORD hDeviceContext );
void DEM_PowerDown( DWORD hDeviceContext );
DWORD DEM_Read( DWORD hOpenContext, LPVOID pBuffer, DWORD Count );
DWORD DEM_Write( DWORD hOpenContext, LPCVOID pBuffer, DWORD Count );
DWORD DEM_Seek( DWORD hOpenContext, long Amount, WORD Type );
#define IOCTL_DRIVER_DEMO 42
#define ELECTROMOTOR_6 (ELECTROMOTOR_1+6)
#define ELECTROMOTOR_7 (ELECTROMOTOR_1+7)
unsigned long ELECTROMOTOR_1;
unsigned long ELECTROMOTOR_GPACON;
unsigned long ELECTROMOTOR_GPADATA;
PHYSICAL_ADDRESS GPACON={0X56000000,0};
PHYSICAL_ADDRESS GPADATA={0X56000004,0};
PHYSICAL_ADDRESS EMOTOR_1={0X10000000,0};
// Not exposed by the Device Driver
void DBGOut(DWORD dwValue);
HANDLE hMem=NULL;
DWORD dwCount;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch ( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH:
OutputDebugString(L"MyDriver - DLL_PROCESS_ATTACH\n");
break;
case DLL_PROCESS_DETACH:
OutputDebugString(L"MyDriver - DLL_PROCESS_DETACH\n");
break;
case DLL_THREAD_ATTACH:
OutputDebugString(L"MyDriver - DLL_THREAD_ATTACH\n");
break;
case DLL_THREAD_DETACH:
OutputDebugString(L"MyDriver - DLL_THREAD_DETACH\n");
break; }
return TRUE;
}
DWORD DEM_Init( LPCTSTR pContext, LPCVOID lpvBusContext)
{
OutputDebugString(L"MyDriver - DEM_Init - Context: ");
OutputDebugString(pContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_Init\n");
ELECTROMOTOR_GPACON=(ULONG)MmMapIoSpace(GPACON,4,FALSE);
ELECTROMOTOR_GPADATA=(ULONG)MmMapIoSpace(GPADATA,4,FALSE);
ELECTROMOTOR_1=(ULONG)MmMapIoSpace(EMOTOR_1,8,FALSE);
return 0x1234;
}
BOOL DEM_Deinit( DWORD hDeviceContext )
{
OutputDebugString(L"MyDriver - DEM_Deinit\n");
OutputDebugString(L"MyDriver - ~ DEM_Deinit\n");
return TRUE;
}
DWORD DEM_Open( DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode )
{
OutputDebugString(L"MyDriver - DEM_Open\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_Open\n");
return 0x5678;
}
BOOL DEM_Close( DWORD hOpenContext )
{
OutputDebugString(L"MyDriver - DEM_Close\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_Close\n");
return TRUE;
}
BOOL DEM_IOControl( DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut )
{
OutputDebugString(L"MyDriver - DEM_IOControl\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_IOControl\n");
return TRUE;
}
void DEM_PowerUp( DWORD hDeviceContext )
{
OutputDebugString(L"MyDriver - DEM_PowerUp\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_PowerUp\n");
}
void DEM_PowerDown( DWORD hDeviceContext )
{
OutputDebugString(L"MyDriver - DEM_PowerDown\n");
OutputDebugString(L"hDeviceContext - ");
DBGOut(hDeviceContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_PowerDown\n");
}
DWORD DEM_Read( DWORD hOpenContext, LPVOID pBuffer, DWORD Count )
{
DWORD dwRetCount=0xffff; // default to error
OutputDebugString(L"MyDriver - DEM_Read\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
if (NULL != hMem) {
dwRetCount=dwCount;
memcpy(pBuffer,hMem,dwCount);
}
OutputDebugString(L"MyDriver - ~ DEM_Read\n");
return dwRetCount;
}
DWORD DEM_Write( DWORD hOpenContext, LPCVOID pBuffer, DWORD Count )
{
OutputDebugString(L"MyDriver - DEM_Write\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
if (NULL != hMem) {
LocalFree(hMem);
}
hMem=LocalAlloc(LPTR,Count);
memcpy(hMem,pBuffer,Count);
dwCount=Count;
OutputDebugString(L"MyDriver - ~ DEM_Write\n");
return Count;
}
DWORD DEM_Seek( DWORD hOpenContext, long Amount, WORD Type )
{
OutputDebugString(L"MyDriver - DEM_Seek\n");
OutputDebugString(L"hOpenContext - ");
DBGOut(hOpenContext);
OutputDebugString(L"\n");
OutputDebugString(L"MyDriver - ~ DEM_Seek\n");
return 0;
}
void DBGOut(DWORD dwValue)
{
TCHAR tcTemp[10];
wsprintf(tcTemp,L"%ld",dwValue);
OutputDebugString(tcTemp);
}
/////////////////SOURCES文件
WINCEREL=1
RELEASETYPE=LOCAL
_ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;
_OEMINCPATH=$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc;
TARGETNAME=LEDDRIVER
FILE_VIEW_ROOT_FOLDER= \
ReadMe.txt \
StdAfx.cpp \
prelink.bat \
postlink.bat \
FILE_VIEW_RESOURCE_FOLDER= \
FILE_VIEW_INCLUDES_FOLDER= \
StdAfx.h \
INCLUDES= \
$(_WINCEROOT)\PUBLIC\COMMON\DDK\INC;$(_WINCEROOT)\PUBLIC\COMMON\OAK\INC; \
SOURCES= \
LEDDRIVER.cpp \
TARGETTYPE=DYNLINK
PRECOMPILED_CXX=1
PRECOMPILED_PCH=StdAfx.pch
TARGETLIBS= \
$(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib\
$(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\ceddk.lib\ ......{1}
PRECOMPILED_OBJ=StdAfx.obj
PRECOMPILED_INCLUDE=StdAfx.h
CDEFINES=$(CDEFINES) -DLEDDRIVER_EXPORTS
POSTLINK_PASS_CMD=postlink.bat
PRELINK_PASS_CMD=prelink.bat
FILE_VIEW_PARAMETER_FOLDER= \
LEDDRIVER.bib \
LEDDRIVER.reg \
LEDDRIVER.dat \
LEDDRIVER.db \
LEDDRIVER.def \
ProjSysgen.bat \
我在SOURCES文件中的
TARGETLIBS 不加(1)编译出现连接错误
TARGETLIBS 加(1)编译出现NMAKE : U1073: don't know how to make错误