Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
AnswerRe: Why can I save the error information into the table of SQL server ? Pin
Wendelius28-Sep-15 17:57
mentorWendelius28-Sep-15 17:57 
GeneralRe: Why can I save the error information into the table of SQL server ? Pin
Member 245846729-Sep-15 17:36
Member 245846729-Sep-15 17:36 
GeneralRe: Why can I save the error information into the table of SQL server ? Pin
Wendelius29-Sep-15 18:15
mentorWendelius29-Sep-15 18:15 
GeneralRe: Why can I save the error information into the table of SQL server ? Pin
Member 24584672-Oct-15 2:56
Member 24584672-Oct-15 2:56 
QuestionSitemapnode(breadcrumb) value changes with multiple users Pin
nitin_ion28-Sep-15 4:09
nitin_ion28-Sep-15 4:09 
AnswerRe: Sitemapnode(breadcrumb) value changes with multiple users Pin
Pete O'Hanlon28-Sep-15 4:58
mvePete O'Hanlon28-Sep-15 4:58 
AnswerRe: Sitemapnode(breadcrumb) value changes with multiple users Pin
Richard Deeming28-Sep-15 6:30
mveRichard Deeming28-Sep-15 6:30 
QuestionPort some C++ code which contains WriteFile to C# Pin
Member 1206160028-Sep-15 1:48
Member 1206160028-Sep-15 1:48 
I have some C++ code which is based on WriteFile. To my understanding it uses this method to write: *both* to normal files on my filesystem and to USB also (HASP).


Basically this is the code in the constructor of the C++ class:

C++
if(isOpen) return true ;
       char PortNameUNC[256] ;
       if(PortName[0] != '\\') strcpy(PortNameUNC, "\\\\.\\") ;
       else *PortNameUNC = 0 ;
       strcat(PortNameUNC, PortName) ;
       *hDev = CreateFile(PortNameUNC, GENERIC_READ|GENERIC_WRITE, 0, NULL,
         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
       if(*hDev == INVALID_HANDLE_VALUE) return false ;
       DCB *dcb = new DCB ;
       memset(dcb, 0x00, sizeof(DCB)) ;
       dcb->DCBlength       = sizeof(DCB);
       dcb->BaudRate        = BaudRate;
       dcb->Parity          = Parity;
       dcb->StopBits        = StopBits;
       dcb->ByteSize        = ByteSize;
       dcb->fBinary         = TRUE;
       dcb->fDsrSensitivity = 0;
       dcb->fDtrControl     = (DTR ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE) ;
       dcb->fRtsControl     = (RTS ? RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE) ;
       dcb->fOutxCtsFlow    = (CTS ? 1 : 0) ;
       dcb->fOutxDsrFlow    = (DSR ? 1 : 0) ;
       dcb->fOutX           = (XonnXoff ? 1 : 0) ;
       dcb->fInX            = 0 ;
       if(!SetCommState(*hDev, dcb))
       {
         delete dcb ;
         CloseHandle(*hDev) ;
         *hDev = INVALID_HANDLE_VALUE ;
         return false;
       }
       delete dcb ;
       this->BaudRate = BaudRate;
       this->Parity = Parity;
       this->StopBits = StopBits;
       this->ByteSize = ByteSize;

       if(!SetTimeOut(readTimeOut, ReadIntervalTimeout) || !Reset())
       {
         CloseHandle(*hDev) ;
         *hDev = INVALID_HANDLE_VALUE ;
         return false;
       }
       isOpen = true ;
       return true ;

And then there is method like write which simply calls `WriteFile` method - and passes the handle created in the constructor and data (I think this way it can write both to USB and my hard drive?)

Why is this `DCB` used additionally and also the `SetCommState` in the constructor?

What is the easiest way to mimic this behaviour in C#??? Do I need `SerialPort` class?

modified 28-Sep-15 9:32am.

AnswerRe: WriteFile equivalent in C# Pin
Pete O'Hanlon28-Sep-15 3:00
mvePete O'Hanlon28-Sep-15 3:00 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 3:18
Member 1206160028-Sep-15 3:18 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 3:21
Member 1206160028-Sep-15 3:21 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 3:40
mveDave Kreskowiak28-Sep-15 3:40 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 3:55
Member 1206160028-Sep-15 3:55 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 4:09
mveDave Kreskowiak28-Sep-15 4:09 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 4:15
Member 1206160028-Sep-15 4:15 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 4:25
mveDave Kreskowiak28-Sep-15 4:25 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 4:32
Member 1206160028-Sep-15 4:32 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 7:07
mveDave Kreskowiak28-Sep-15 7:07 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 7:31
Member 1206160028-Sep-15 7:31 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 7:46
Member 1206160028-Sep-15 7:46 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 8:35
mveDave Kreskowiak28-Sep-15 8:35 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 9:06
Member 1206160028-Sep-15 9:06 
GeneralRe: WriteFile equivalent in C# Pin
Dave Kreskowiak28-Sep-15 12:19
mveDave Kreskowiak28-Sep-15 12:19 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 20:25
Member 1206160028-Sep-15 20:25 
GeneralRe: WriteFile equivalent in C# Pin
Member 1206160028-Sep-15 20:28
Member 1206160028-Sep-15 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.