VeecoTech
VeecoTech

Reputation: 2143

how to convert this to C#

Hi i have the following code which i would like to convert to C#. Could you share some light here how can i convert those to C#? i am not well familiar with C++. Especially on the function DeviceIoControl which it is calling the WinBase API. In C#, what function should i use to replace DeviceIOCOntrol?

shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
   accessMode        = GENERIC_READ | GENERIC_WRITE;

   sprintf(ff, "\\\\.\\%s", device);
    hFile = CreateFile(ff, accessMode, shareMode, NULL, OPEN_EXISTING, 0, NULL);


   if(hFile == INVALID_HANDLE_VALUE) {
           *response = -1;
           sprintf((response + 1), "Failed to open device %s", device); 
           return;
   }


    status = DeviceIoControl(hFile,
                                           IOCTL_SCSI_GET_ADDRESS,
                                                    NULL,
                                                    0,
                                                    inquiry_data,
                                                    sizeof(inquiry_data),
                                                    &returned,
                                                    FALSE);

Upvotes: 1

Views: 375

Answers (2)

Jerry Coffin
Jerry Coffin

Reputation: 490623

This is retrieving the SCSI bus #, ID # on that bus, and LUN on that ID. You'll probably need to figure out what's being done with that to figure out how to translate/replace it meaningfully. If memory serves, you can retrieve some of the same information via WMI, but there's a pretty fair chance that won't do a lot of good -- the primary uses for this information is to pass it back when making other DeviceIoControl calls.

Upvotes: 1

Simon Mourier
Simon Mourier

Reputation: 139226

You must use P/Invoke interop to access DeviceIoControl. Here is a link that has similar calls and should be a good starting point: Defrag API C# wrappers

Upvotes: 2

Related Questions