Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CreateFile problem

CreateFile problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondebuggingannouncement
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Senkwe Chanda
    wrote on last edited by
    #1

    Ok, this is a revisit to the problem that Chris Losinger tried to help me with. I had wrongly thought GetFileSize was the problem, he helped me determine that was not the case, thanks again Chris!! I have an app associated with a certain file type. When I double click the file, it opens up my app. In this way the file name is passed to the app. This works fine and I have proved it by popping a message box with the filename on it. As you can see below m_EncryptedFilePath is the file name in question.

    HANDLE hOriginal = ::CreateFile(m_EncryptedFilePath,
    GENERIC_READ,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

    Now, in DEBUG mode, all is dandy. hOriginal is not NULL. But in RELEASE mode, it is NULL even though the correct file name is passed through in each case. Could it be file permissions?? Access rights?? The way I'm associating the file with the app?? By the way, release mode works fine if I hard code the file name like so

    HANDLE hOriginal = ::CreateFile("c:\\myfile.abc",
    GENERIC_READ,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

    So I'm completely at my wits end over this at the moment. Any and all comments will be appreciated. Senwe And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

    K O 2 Replies Last reply
    0
    • S Senkwe Chanda

      Ok, this is a revisit to the problem that Chris Losinger tried to help me with. I had wrongly thought GetFileSize was the problem, he helped me determine that was not the case, thanks again Chris!! I have an app associated with a certain file type. When I double click the file, it opens up my app. In this way the file name is passed to the app. This works fine and I have proved it by popping a message box with the filename on it. As you can see below m_EncryptedFilePath is the file name in question.

      HANDLE hOriginal = ::CreateFile(m_EncryptedFilePath,
      GENERIC_READ,
      FILE_SHARE_READ,
      NULL,
      OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL,
      NULL);

      Now, in DEBUG mode, all is dandy. hOriginal is not NULL. But in RELEASE mode, it is NULL even though the correct file name is passed through in each case. Could it be file permissions?? Access rights?? The way I'm associating the file with the app?? By the way, release mode works fine if I hard code the file name like so

      HANDLE hOriginal = ::CreateFile("c:\\myfile.abc",
      GENERIC_READ,
      FILE_SHARE_READ,
      NULL,
      OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL,
      NULL);

      So I'm completely at my wits end over this at the moment. Any and all comments will be appreciated. Senwe And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      What does GetLastError() return?

      S 2 Replies Last reply
      0
      • K KarstenK

        What does GetLastError() return?

        S Offline
        S Offline
        Senkwe Chanda
        wrote on last edited by
        #3

        Good question, in DEBUG mode it returns 0, implying all is well. That's why when I'm debugging everything works. The release version of CreateFile returns a NULL handle. Perhaps I should place a FormatMessage and populate a MessageBox to retrieve GetLastError in my release mode? And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

        K 1 Reply Last reply
        0
        • K KarstenK

          What does GetLastError() return?

          S Offline
          S Offline
          Senkwe Chanda
          wrote on last edited by
          #4

          GetLastError returns the following...

          The filename, directoryname, or volume label syntax is incorrect

          Which is what I assumed...but I just don't see how or why. And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

          1 Reply Last reply
          0
          • S Senkwe Chanda

            Ok, this is a revisit to the problem that Chris Losinger tried to help me with. I had wrongly thought GetFileSize was the problem, he helped me determine that was not the case, thanks again Chris!! I have an app associated with a certain file type. When I double click the file, it opens up my app. In this way the file name is passed to the app. This works fine and I have proved it by popping a message box with the filename on it. As you can see below m_EncryptedFilePath is the file name in question.

            HANDLE hOriginal = ::CreateFile(m_EncryptedFilePath,
            GENERIC_READ,
            FILE_SHARE_READ,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

            Now, in DEBUG mode, all is dandy. hOriginal is not NULL. But in RELEASE mode, it is NULL even though the correct file name is passed through in each case. Could it be file permissions?? Access rights?? The way I'm associating the file with the app?? By the way, release mode works fine if I hard code the file name like so

            HANDLE hOriginal = ::CreateFile("c:\\myfile.abc",
            GENERIC_READ,
            FILE_SHARE_READ,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

            So I'm completely at my wits end over this at the moment. Any and all comments will be appreciated. Senwe And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

            O Offline
            O Offline
            Ollie
            wrote on last edited by
            #5

            Hi, Sounds like a memory allocation\deallocation problem with 'm_EncryptedFilePath' especially if the path is correct('\\' etc) and it works when you hard code the path. What type of string is 'm_EncryptedFilePath'?

            S 1 Reply Last reply
            0
            • O Ollie

              Hi, Sounds like a memory allocation\deallocation problem with 'm_EncryptedFilePath' especially if the path is correct('\\' etc) and it works when you hard code the path. What type of string is 'm_EncryptedFilePath'?

              S Offline
              S Offline
              Senkwe Chanda
              wrote on last edited by
              #6

              Hi Ollie, it's a WTL CString. I've always used it as a drop in replacement for MFC's CString in most cases. And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

              O 1 Reply Last reply
              0
              • S Senkwe Chanda

                Good question, in DEBUG mode it returns 0, implying all is well. That's why when I'm debugging everything works. The release version of CreateFile returns a NULL handle. Perhaps I should place a FormatMessage and populate a MessageBox to retrieve GetLastError in my release mode? And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #7

                If you think, that to populate a MessageBox is the right answer, you have to do it. (If you know what I mean) I also have these type of problems and I have to fix them. The first step is to get a "handle" to the problem. You have there a member variable for the file name. I guess it is a CString -> (LPCSTR) cast is best practise. Try also Release Output of it to check its ok. ( I Do a Findfile to check this).:~

                S 1 Reply Last reply
                0
                • K KarstenK

                  If you think, that to populate a MessageBox is the right answer, you have to do it. (If you know what I mean) I also have these type of problems and I have to fix them. The first step is to get a "handle" to the problem. You have there a member variable for the file name. I guess it is a CString -> (LPCSTR) cast is best practise. Try also Release Output of it to check its ok. ( I Do a Findfile to check this).:~

                  S Offline
                  S Offline
                  Senkwe Chanda
                  wrote on last edited by
                  #8

                  KarstenK wrote: The first step is to get a "handle" to the problem. Yep and my assumption was correct, the file isn't being recognised. GetLastError confirms this. KarstenK wrote: I guess it is a CString -> (LPCSTR) cast is best practise Well yes, a WTL CString, not an MFC CString :-) And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

                  1 Reply Last reply
                  0
                  • S Senkwe Chanda

                    Hi Ollie, it's a WTL CString. I've always used it as a drop in replacement for MFC's CString in most cases. And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

                    O Offline
                    O Offline
                    Ollie
                    wrote on last edited by
                    #9

                    have you tried making a local copy of the string and then using it, sorry not up to speed on WTL CString, what is the underlying type?

                    S 1 Reply Last reply
                    0
                    • O Ollie

                      have you tried making a local copy of the string and then using it, sorry not up to speed on WTL CString, what is the underlying type?

                      S Offline
                      S Offline
                      Senkwe Chanda
                      wrote on last edited by
                      #10

                      No prob Ollie, it's a great library as you already know I'm sure, please do explore it for your new win32 work :-) The underlying type is LPTSTR. I think you're onto something though. Let me explore the CString header file more carefully. And when God, who created the entire universe with all of its glories, decides to deliver a message to humanity, He WILL NOT use, as His messenger, a person on cable TV with a bad hairstyle.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups