My loop doesn't work, need some guidance..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cosmos22
    New Member
    • Feb 2008
    • 9

    My loop doesn't work, need some guidance..

    The loop below doesn't work, I was wondering if anyone can help me. I need to create an infinate loop around the while condition.
    The error states that 'd' is undeclared

    Thank you all :)

    [code=cpp]
    #include "windows.h"
    #include "winioctl.h "
    #include <string>
    #include <iostream>
    using std::string;
    using namespace std;


    int main(int argc, char* argv[])
    {


    string sdrive("\\\\.\\ e:");

    HANDLE hcd = CreateFile(sdri ve.c_str(),
    GENERIC_READ,
    FILE_SHARE_READ ,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_ READONLY,
    NULL);




    while(1)
    {

    DeviceIoControl (hcd, IOCTL_STORAGE_E JECT_MEDIA, NULL, 0, NULL, 0,
    &d,NULL);
    DeviceIoControl (hcd, IOCTL_STORAGE_L OAD_MEDIA, NULL, 0, NULL, 0,
    &d,NULL);

    }
    CloseHandle(hcd );
    return 0;

    }[/code]
    Last edited by sicarie; Feb 19 '08, 04:36 PM. Reason: Code tagsa re [code=cpp] and after your code [/code]. Please use them. They want to be used. They like to be used.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Well, define d.

    BTW: You are not using <tchar.h> and none of the TCHAR mappings. All Windows is Unicode and this ASCII stuff you are writing is converted to Unicode by the ASCII Win32 function wwho then calls the Unicode verison of that Win32 function, and then converts any returned Unicide strings back to ASCII and then returns to you.

    You have to use <tchar>. That means _tmain(), etc...

    Comment

    • cosmos22
      New Member
      • Feb 2008
      • 9

      #3
      Originally posted by weaknessforcats
      Well, define d.

      BTW: You are not using <tchar.h> and none of the TCHAR mappings. All Windows is Unicode and this ASCII stuff you are writing is converted to Unicode by the ASCII Win32 function wwho then calls the Unicode verison of that Win32 function, and then converts any returned Unicide strings back to ASCII and then returns to you.

      You have to use <tchar>. That means _tmain(), etc...
      I've defined d, so is it not possible to implement a loop in this program using what I've made? How would I go about using the <tchar.h> variable?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        The d is the seventh argument in the call to DeviceIoControl and it is not defined in your code. That has nothing to so with being a loop.

        As to tchar.h, read this: http://msdn2.microsoft.com/en-us/lib...42(VS.85).aspx.

        Comment

        Working...