Help for conversion from evc++ to c#

M

manohar.bang

Hello ,
I am trying to write a block device driver for sd cards in c#.. i have
it in evc++.. i am not very familiar with c#.. could some one point me
as to how this could be done..
in the following code .. i a writing the contents of the file to
specific location on the SD card.

I did try in c#.. but i couldnt find much help.. i used the
coredll.dll.. however i am not sure of the parameter to be passed to
functions like CreateFile and DeviceIOControl function..

regards,
Manu

void CSdDemoDlg::OnRawWrite()
{
// TODO: Add your control notification handler code here


HANDLE hDevice1
=CreateFile(L"DSK1:",GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
SG_REQ lpInBuf1;
DWORD dwDummy1 = 3;
char *lpOutBuf1;
lpOutBuf1 = ( char *)malloc(512);
memset(lpOutBuf1, 0x00, 512); // only to see the changes
char pBuffer[512];
FILE *hDrv2=fopen("\\sdInput.txt","rb");
if (INVALID_HANDLE_VALUE == hDrv2) {
OutputDebugString(L"Failed to open Driver for read...\n");
} else {
size_t sz_read= fread(&pBuffer,512,1,hDrv2);
fclose(hDrv2);
}
strcpy(( char*)lpOutBuf1,( char *)pBuffer);

lpInBuf1.sr_start =0xFF; //0x0018555; // physical sector
lpInBuf1.sr_num_sec = 1; // number of sectors sector
lpInBuf1.sr_num_sg = 1;
lpInBuf1.sr_status = 0; //ERROR_SUCCESS;
lpInBuf1.sr_callback =NULL;// callbackDiskRead;
lpInBuf1.sr_sglist[0].sb_buf = ((LPBYTE)
MapPtrToProcess(lpOutBuf1,GetCurrentProcess()));
lpInBuf1.sr_sglist[0].sb_len = 512 * lpInBuf1.sr_num_sec;

BOOL bRet=DeviceIoControl(hDevice1, // Handle to the device
IOCTL_DISK_WRITE, // IOCTL for the operation
&lpInBuf1, // LP to a buffer (input data)
sizeof(lpInBuf1), // Size in Bytes of input data buffer

lpOutBuf1, // LP to a buffer for output data
sizeof(lpOutBuf1), // Size in Bytes of output buffer
&dwDummy1, // LP to variable (size of data in out
buffer)
NULL);
CloseHandle(hDevice1);
if(bRet==0)
{
MessageBox(MB_OK,(TCHAR *)lastRawWriteError,MB_ICONINFORMATION|MB_OK);
}

}
 
G

Guest

You can't create a driver in C#. CF has no CLR hosting support, so it's
impossible to get the system to load it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top