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. Windows API
  4. a small problem with function

a small problem with function

Scheduled Pinned Locked Moved Windows API
help
7 Posts 4 Posters 44 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Sir, I have used a combination of GetLogicalDriveStrings and GetDriveType to add the strings of removable drive in the combo box. In order to use the string for some iteration purpose I copied the string using GetDlgItemText function

    wchar_t buf[10];
    GetDlgItemText(hWnd, ID_COMBO, buf, 9);

    buf contains the string of the removable drive e.g H:\ I am willing to find the no.of shortcuts found in my removable drive, I have successfully achieved my will using FindFirstFile and FindNextFile functions but by using the maual locations like this

    wchar_t* location = L"H:\\*lnk";

    but when I use my buf like this I get an error

    countOfShortcuts(wchar_t buffer[10])
    {
    wchar_t location = buffer + "*lnk"
    /*
    then my code

    */
    }

    Here the function gets the "buf" value. I checked with a message box and found that the drive is correctly acquired with my function. But I can't add it with some locations in order to do the iteration. Error message: Two pointers cannot be added What I have tried: This a quiet rare experience to me so I tired with strcpy, memcpy, adding * the & befor the buffer in this part "wchar_t location = buffer + "*lnk" but every thing is complicating the issues so I did considered to ask some help. Thank you sir for your time

    Richard Andrew x64R G 2 Replies Last reply
    0
    • L Lost User

      Sir, I have used a combination of GetLogicalDriveStrings and GetDriveType to add the strings of removable drive in the combo box. In order to use the string for some iteration purpose I copied the string using GetDlgItemText function

      wchar_t buf[10];
      GetDlgItemText(hWnd, ID_COMBO, buf, 9);

      buf contains the string of the removable drive e.g H:\ I am willing to find the no.of shortcuts found in my removable drive, I have successfully achieved my will using FindFirstFile and FindNextFile functions but by using the maual locations like this

      wchar_t* location = L"H:\\*lnk";

      but when I use my buf like this I get an error

      countOfShortcuts(wchar_t buffer[10])
      {
      wchar_t location = buffer + "*lnk"
      /*
      then my code

      */
      }

      Here the function gets the "buf" value. I checked with a message box and found that the drive is correctly acquired with my function. But I can't add it with some locations in order to do the iteration. Error message: Two pointers cannot be added What I have tried: This a quiet rare experience to me so I tired with strcpy, memcpy, adding * the & befor the buffer in this part "wchar_t location = buffer + "*lnk" but every thing is complicating the issues so I did considered to ask some help. Thank you sir for your time

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      You can't add strings like that in C++. You must create a second buffer and copy both strings into it:

      wchar_t NewBuf[MAX_PATH+1] = {0};

      strncat_s(NewBuf, MAX_PATH, location, /* Put length of "location" here */);

      strncat_s(NewBuf, MAX_PATH, L"*lnk", 4);

      // Use NewBuf .......

      The difficult we do right away... ...the impossible takes slightly longer.

      L 1 Reply Last reply
      0
      • L Lost User

        Sir, I have used a combination of GetLogicalDriveStrings and GetDriveType to add the strings of removable drive in the combo box. In order to use the string for some iteration purpose I copied the string using GetDlgItemText function

        wchar_t buf[10];
        GetDlgItemText(hWnd, ID_COMBO, buf, 9);

        buf contains the string of the removable drive e.g H:\ I am willing to find the no.of shortcuts found in my removable drive, I have successfully achieved my will using FindFirstFile and FindNextFile functions but by using the maual locations like this

        wchar_t* location = L"H:\\*lnk";

        but when I use my buf like this I get an error

        countOfShortcuts(wchar_t buffer[10])
        {
        wchar_t location = buffer + "*lnk"
        /*
        then my code

        */
        }

        Here the function gets the "buf" value. I checked with a message box and found that the drive is correctly acquired with my function. But I can't add it with some locations in order to do the iteration. Error message: Two pointers cannot be added What I have tried: This a quiet rare experience to me so I tired with strcpy, memcpy, adding * the & befor the buffer in this part "wchar_t location = buffer + "*lnk" but every thing is complicating the issues so I did considered to ask some help. Thank you sir for your time

        G Offline
        G Offline
        Graham Breach
        wrote on last edited by
        #3

        Since this is in the Windows API forum, here's the PathCchAppend function (Windows)[^] - it performs the string concatenation and adds in extra backslashes if they are required.

        L 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          You can't add strings like that in C++. You must create a second buffer and copy both strings into it:

          wchar_t NewBuf[MAX_PATH+1] = {0};

          strncat_s(NewBuf, MAX_PATH, location, /* Put length of "location" here */);

          strncat_s(NewBuf, MAX_PATH, L"*lnk", 4);

          // Use NewBuf .......

          The difficult we do right away... ...the impossible takes slightly longer.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          To sir Richard Andrew x64, Sir, I did tried your method but I am getting an error named " cannot convert from wchar_t* to char* " what shall I do now? I did used type conversion but it does not help me because out put always jumps to the else part which leads to the failure of detection of shortcuts. Kindly help me with this Thank you sir for your kind help and time.

          J 1 Reply Last reply
          0
          • L Lost User

            To sir Richard Andrew x64, Sir, I did tried your method but I am getting an error named " cannot convert from wchar_t* to char* " what shall I do now? I did used type conversion but it does not help me because out put always jumps to the else part which leads to the failure of detection of shortcuts. Kindly help me with this Thank you sir for your kind help and time.

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #5

            Use wcsncat_s instead of strncat_s.

            L 1 Reply Last reply
            0
            • J Jochen Arndt

              Use wcsncat_s instead of strncat_s.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Thank you sir for your kind help. It worked

              1 Reply Last reply
              0
              • G Graham Breach

                Since this is in the Windows API forum, here's the PathCchAppend function (Windows)[^] - it performs the string concatenation and adds in extra backslashes if they are required.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Thank you sir for your kind help and time

                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