quaiser
August 27th, 2004, 05:27 AM
hi all
i am writing an application to access the generic device driver of HID class.
i get the handle of the device by createfile() and other API's of the window but when i try to read and write (writefile and readfile )using the handle i get error number one as described in windowssystem errors.
can anyone let me know the error i am committing and guide me or if any one have any source then plz share with me
thanks
quaiser
kathir4
September 5th, 2004, 10:23 PM
Here is the complete code it dials ISP phone no 172233 via modem connected to com port 1 with baud rate 14400
u can change settings for com port and baud rate locating the following functions in the programe and change accordingly
handle= CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE,1,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
dcb.BaudRate = 14400 ;
My email id is kathir4@sancharnet.in
PROGRAME
#include <windows.h>
#include <stdio.h>
void abcchar(unsigned char a)
{
FILE * fp;
fp=fopen("c:\\z.txt","a+");
fprintf(fp,"%x..%d..%c\n",a,a,a);
fclose(fp);
}
HDC hdc ;
HANDLE handle ;
HWND hwnd ;
int column, row, xwidth, yheight ;
long threadid, bytesrecd, byteswritten;
long _stdcall wndcallback(HWND wnd,unsigned int umsg,unsigned int wparam,long lparam);
DCB dcb;
WNDCLASS wndclass;
MSG msg;
char writestr[200];char ctemp;
long _stdcall commcallback()
{
unsigned char readstr[2];
while (1)
{ ReadFile(handle,readstr,1,(unsigned long *)&bytesrecd,0);
abcchar(readstr[0]);
if (readstr[0] == 13 )
column = 0 ;
if (readstr[0] == 10)
row++;
if (readstr[0] == 0x08)
column -- ;
if (readstr[0] != 0x0a && readstr[0] != 0x0d)
{
TextOut(hdc,column*xwidth,row*yheight,(const char *)readstr,1);
if (column < 79)
column++ ;
else
{
column = 0;
row++;
}
}
}
return 1;
}
int _stdcall WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance,LPSTR lpszcmdline, int ncmdshow )
{
wndclass.lpfnWndProc=wndcallback;
wndclass.hInstance=hinstance;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); ;
wndclass.lpszClassName="wclass";
RegisterClass(&wndclass);
hwnd=CreateWindow("wclass","hi",WS_OVERLAPPEDWINDOW,0,0,0,0,0,0,hinstance,0);
xwidth = 8;
yheight = 19;
ShowWindow( hwnd, 3 ) ;
hdc=GetDC(hwnd);
handle= CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE,1,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL );
dcb.DCBlength = sizeof( DCB ) ;
GetCommState( handle, &dcb ) ;
dcb.BaudRate = 14400 ;
SetCommState( handle, &dcb ) ;
CreateThread(0,0,(LPTHREAD_START_ROUTINE) commcallback,0,0, (unsigned long *)&threadid );
strcpy(writestr,"atdt172233\r");
WriteFile(handle,writestr,strlen(writestr),(unsigned long *)&byteswritten,0) ;
while (GetMessage( &msg, 0, 0, 0 ))
{
TranslateMessage( &msg ) ;
DispatchMessage( &msg ) ;
}
return 0 ;
}
long _stdcall wndcallback(HWND wnd,unsigned int umsg,unsigned int wparam,long lparam)
{
if(umsg == WM_CHAR)
{
ctemp = wparam ;
// WriteFile(handle,writestr,1,(unsigned long *)&byteswritten,0) ;
WriteFile(handle,&ctemp,1,(unsigned long *)&byteswritten,0) ;
}
if(umsg == WM_DESTROY)
{
ReleaseDC(wnd,hdc);
PostQuitMessage( 0 ) ;
}
return( DefWindowProc( wnd, umsg, wparam, lparam ) ) ;
}