|
Assuming you have the window handle of the control, first send it a LVM_GETITEMCOUNT message. Then for each item, send the control a LVM_GETITEMTEXT message.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
this item has two windows,you can find the editbox's handle to read text from it.
|
|
|
|
|
do you have happen this problem:
str1's content is equivalent to str2,str3,str4 and str5,how to solve the problem, thank you very much.
|
|
|
|
|
Okay I am trying to lock CD drive (F: here) with the code shown. But DeviceIoControl is returning "error 87: Parameter not correct". Please someone help me. I cannot find out which parameter is incorrcet.
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
void ShowError(void);
int main(){
char szVolume[] = "\\\\.\\F:";
HANDLE hVolume;
DWORD dwBytes = 0;
PREVENT_MEDIA_REMOVAL pmr;
pmr.PreventMediaRemoval = TRUE;
hVolume = CreateFile(szVolume,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if(hVolume==INVALID_HANDLE_VALUE){
ShowError();
exit(1);
}
if(DeviceIoControl(hVolume,IOCTL_STORAGE_EJECTION_CONTROL,(LPVOID)&pmr,(DWORD)sizeof(pmr),NULL,0,&dwBytes,NULL)==FALSE){
ShowError();
}
CloseHandle(hVolume);
return 0;
}
|
|
|
|
|
I can't find an error, but maybe you open the device in a wrong way?
MSDN says:
"hDevice [in]
A handle to the device. To obtain a device handle, call the CreateFile function.
Files must be opened with the FILE_READ_ATTRIBUTES access right. For more information, see File Security and Access Rights."
You try to open your device with generic read and write access.
Sorry buts the only thing I found, what could maybe explain this error.
Has hVolume the right value?
(Your check is right, but i wonder what GetLastError() says.)
Edit:
Maybe you should also change your sharing parameter in your CreateFile call (for example try 0 -> no share).
|
|
|
|
|
Yes hVolume is right value. GetLastError returns 0.
GENERIC_READ already has FILE_READ_ATTRIBUTES
Tried using 0 for File sharing but still DeviceIoControl gives error 87 parameter not correct
Thanks for replying, I appreciate it.
|
|
|
|
|
Are you completely sure about F:?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Yes my DVD drive is F:. and handle returned by CreateFile is valid too.
Thanks for replying
|
|
|
|
|
Patcher32 wrote: PREVENT_MEDIA_REMOVAL pmr;
Isn't this used with IOCTL_STORAGE_MEDIA_REMOVAL ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
According to this[^] it is also used with IOCTL_STORAGE_EJECTION_CONTROL.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Two MSDN sites that contradict each other. No surprise there!
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Okay I finally got it to work. YAY!
I made this change : pmr.PreventMediaRemoval = (BYTE)TRUE; in the original code I posted.
But MSDN says the PreventMediaRemoval member is BOOLEAN ? Thanks for confusing me MSDN!
The value has to be BYTE . So setting it to 1 locks drive from being ejected. Setting it to 0 unlocks the drive from ejecting.
|
|
|
|
|
"But MSDN says the PreventMediaRemoval member is BOOLEAN? Thanks for confusing me MSDN!"
MSDN is right the problem is, that TRUE is a 32 Bit-Value (TRUE and true are not the same). So you send the value 0(FALSE) to your drive. And if I'm right, the function fails if you try to unlock drive you never locked before.
|
|
|
|
|
If I lock with (BYTE)TRUE : works
If I unlock a locked device using (BYTE)FALSE : works
If I try to unlock a device (without locking it first) using (BYTE)FALSE : gives error #22, The device does not recognize command
I think this is expected behavior. Please guide me in right direction if I am doing it wrong.
|
|
|
|
|
I have a C++ program running on Windows XP compiled with Visual C++ 6.0 containing the following code
[code]
if (remove(NewName) != 0)
{
errmsg = strerror(errno);
printf("Removal Error: %s\n", errmsg);
}
if (rename(FileName,NewName) != 0)
{
errmsg = strerror(errno);
printf("Rename Error: %s\n", errmsg);
}
[/code]
and this fails, offering to send a message to Microsoft about the error of my ways.
The file I want to rename(FileName) does exist and the file I want to rename it to(NewName) does not and none of my error messages appear.
Please make suggestions on how I should fix this.
Regards,
Alf Stockton
|
|
|
|
|
StrayGrey wrote: if (remove(NewName) != 0)
What does remove() return?
StrayGrey wrote: errmsg = strerror(errno);
How is errmsg declared?
Hve you tried DeleteFile() or SHFileOperation() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I apparently do not get anything back from remove()
errmsg is defined as
char *errmsg;
Regards,
Alf Stockton
|
|
|
|
|
Have you used the debugger? What types are NewName and FileName?
|
|
|
|
|
I have them defined as:-
char *FileName = "";
char *NewName = "";
Regards,
Alf Stockton
|
|
|
|
|
Again, have you used the debugger? Do FileName and NewName contain valid file names (and paths)?
|
|
|
|
|
The trick that has worked for me is not to define the file names as pointers but rather as arrays.
Regards,
Alf Stockton
|
|
|
|
|
Whether you use
char *NewName = "c:\\somefile.txt";
remove(NewName); or
char NewName[] = "c:\\somefile.txt";
remove(NewName); they both work.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have just run this code and it works fine, so I suspect there is some part that you have not shown that is actually failing. Can you post the full program (assuming it's not hundreds of lines)? Also please surround it with <pre></pre> tags to keep it formatted properly, use the code block button at the top of the edit window.
|
|
|
|
|
Name file variables as arrays not pointers.
Regards,
Alf Stockton
|
|
|
|
|
Hello All,
I am working on a project where I need to catch the windows shutdown event through a windows service running in system account, delay shutdown and execute some shutdown scripts and then once the scripts have been completed the shutdown continues.Kindly suggest me some ways to do this via a windows service developed by me in C++.
Regards,
Kushagra
I hate coding but I luv to develop 
|
|
|
|