a small problem with function
-
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
-
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
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.
-
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
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.
-
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.
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.
-
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.
Use
wcsncat_s
instead ofstrncat_s
. -
Use
wcsncat_s
instead ofstrncat_s
. -
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.