A simple Wince.NET stream drive template

xiaoxiao2021-03-06  55

Author: no.killer@cnemb.com cnemb.com reproduced from the original posted link http://www.cnemb.com/modules.php?op=modload&name=News&file=article&sid=177 in view of the Internet was to me a simple flow Examples of drivers, in fact, PB they have taken examples! But for beginners may not know where to find something, publish a simple stream driver template, may not use it for old birds, but for beginners perhaps! This driver is to save a string! I hope to help beginners!

Driver section #define _win32_winnt 0x0400 # include #include

Handle G_HINSTANCE;

#define buffer 256wchar achbuffer [buffsize];

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- BOOL WINAPI DllEntryPoint (HANDLE hinstDLL, DWORD dwReason, LPVOID / * lpvReserved * /) {switch (dwReason) {case DLL_PROCESS_ATTACH: g_hInstance = hinstDLL; RETAILMSG (1, (TEXT ( "STRINGS: DLL_PROCESS_ATTACH / n "))); return TRUE; case DLL_THREAD_ATTACH: RETAILMSG (1, (TEXT (" STRINGS: DLL_THREAD_ATTACH / n "))); break; case DLL_THREAD_DETACH: RETAILMSG (1, (TEXT (" STRINGS: DLL_THREAD_DETACH / n ") )); break; case DLL_PROCESS_DETACH: RETAILMSG (1, (TEXT ( "STRINGS: DLL_PROCESS_DETACH / n"))); break; #ifdef UNDER_CE case DLL_PROCESS_EXITING: RETAILMSG (1, (TEXT ( "STRINGS: DLL_PROCESS_EXITING / n")) Break; Case DLL_SYSTEM_STARTED: RETAILMSG (1, (Text ("Strings: DLL_SYSTEM_STARTED / N"))))))); Break; #ENDIF}

Return True;}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- Bool str_close (DWord HopenContext) {BOOL BRET = true; Retailmsg (1, (Text ("Strings: Str_Close / N")))))))))))))))))))))))))))))))))))))) -------------------------------------------------- --------------------- // --------------------------- -------------------------------------------------- Bool str_deinit (DWORD HDEVICECONTEXT) {BOOL BRET = True; Retailmsg (1, (Text ("Strings: Str_Deinit / N"))))))))))))); Return Bret;}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- DWORD STR_INIT (DWORD DWCONTEXT) {DWORD DWRET = 0; Retailmsg (1, (Text ("Strings: Str_init / N")))))))

// Initialize Buffer to Zero. Memset (Achbuffer, 0, Bufsize * Sizeof (Wchar));

// set return value to non-zero. Dwret = 1; return dwret;}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- BOOL STR_IOControl (DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut) {BOOL bRet = TRUE; RETAILMSG (1, (TEXT ( "STRINGS: STR_IOControl / n "))); return bret;}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- DWord Str_Open (DWord AccessContext, DWord AccessCode, DWORD Sharemode) {DWORD DWRET = 0; Retailmsg (1, (Text ("Strings: Str_Open / N")))))))))); dwret = 1; // Have to make non-zero for this call to succeed. Return dwret;}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- Void Str_PowerDown (DWord HDeviceContext) {Retailmsg (1, (Text ("str_powerdown / n")))))

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- Void Str_Powerup (DWORD HDEVICECONTEXT) {Retailmsg (1, (Text ("str_powerup / n"))))));

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- DWORD STR_READ (DWORD HopenContext, LPVOID PBUFFER, DWORD Count) {DWORD DWRET = 0; Retailmsg (1, (Text ("Strings: Str_read / N")))))

// copy the smaller of buffer size or string size. DWORD CBBUFFER = WCSLEN (Achbuffer); dwret = min (cbbuffer, count); WCSNCPY ((LPWSTR) PBuffer, Achbuffer, DWRET;

// Return Number of bytes Read. Return Dwret;

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- -------- DWORD STR_SEEK (DWORD HOPENCONTEXT, Long Amount, DWORD TYPE) {DWORD DWRET = 0; Retailmsg (1, (Text ("Strings: Str_Seek / N"))))); Return dwret;} // -------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- ------ DWORD STR_WRITE (DWord Numberofbytes) {DWORD DWRET = 0; Retailmsg (1, (Text ("Strings: Str_Write / N")))))))

// copy the smaller of buffer size or number of bytes the seey sered us (bufsize, numberofbytes); Wcsncpy (Achbuffer, (LPWSTR) PSourcebytes, dwret;

// Return Number of bytes Written Dwret;}

Driver Registry Section [HKEY_LOCAL_MACHINE / DRIVERS / Builtin / Strings] "INDEX" = DWORD: 1 "prefix" = "Str" "DLL" = "string.dll" "Order" = DWORD: 0 call this driver #include #include "stdafx.h"

#define buffer_size 256 // The buffer size is the it is it as the driver's buffer size

Int WinApi WinMain (Hinstance Hinstance, Hinstance Hprevinstance, LPTSTR LPCMDLINE, INT NCMDSHOW) {

// Open the strings driver with read and write access // ------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- , NULL, OPEN_EXISTING, 0, 0); IF (Invalid_Handle_Value == HSTR) {MessageBox (NULL, _T ("Cannot Open str1:"), _T ("stringapp"), MB_OK); return 0;} // Write a String to the driver. // ------------------------------------------- -------------------------- DWORD dwritten = 0; wchar * pstring = text ("this is a test of the string driver. This is on-fli A Test "); Writefile (HSTR, PSTRING, (_TCSLEN (PSTRING) 1), & DWRITTEN, NULL;

// read string from driver. // ----------------------------------------- ---------------------------- Wchar WCH [Buffer_Size]; DWORD DWBYTESREAD = Buffer_Size; Memset (& WCH, '/ 0', Buffer_SIZE * SizeOf (Wchar)); ReadFile (HSTR, WCH, SIZEOF (WCH), & DWBYTESREAD, NULL

MessageBox (NULL, WCH, TEXT ("StringApp"), MB_OK);

// Dischanect from driver. // ------------------------------------------ --------------------------- CloseHandle (HSTR);

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-118117.html

New Post(0)