Hello, I am creating a program that opens and closes your CD drive repeatedly, and fixes your mouse position. I have created an initial while condition that loops the opening and closing of the drive. I was wondering how I can introduce a second infinate loop, fixing the position of the mouse. Using SetCursorPos( X, Y ); I want to make sure that the user has his mouse fixed, so he can't move it. Placing this line of code after the device eject or load function still gives the user enough time to close the application.

Thank you.

*SP* infinite


while(1)
{
DWORD d = 0;
DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
&d, NULL);

DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
}
CloseHandle(hcd);

return 0;
}

Recommended Answers

All 11 Replies

Pray tell, why should we offer assistance toward something that sounds malicious?

I'm not planning on releasing this commercially, I only plan to see its cause and effect, the programming interests me.

Well, I've yet to purchase a virus, so color me unimpressed.

Two nested infinite loops? Is that what you'd call an alpha loop?

Not sure, do you have any ideas?

It's a joke. Google around "infinity" and "cardinality".

Ok, I understand this is potentially malicious, but I AM really not planning on releasing this to people or to any external sites. I just would like to know how to run a second loop inside the other, whilst continuing the other one.

Like most people who do this sort of thing, I'm not stupid enough to do so.

Why would you need to nest infinite loops? Are you saying you want to execute 2 statements as part of a loop, and execute more statements as part of the same loop? Well, add another statement following the first two in the same loop.

I can't, because if I do the below, it opens the drive, then stops on the looped cursor position.


while(1)
{
DWORD d = 0;
DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
while(2)
{
SetCursorPos( X, Y );
}

DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0,
&d, NULL);
}

What should I do?

Does this sort of thing make sense:

while ( 1 )
   {
      // PART A
      DWORD d = 0;
      DeviceIoControl(hcd, IOCTL_STORAGE_EJECT_MEDIA, NULL, 
                      0, NULL, 0, &d, NULL);
      DeviceIoControl(hcd, IOCTL_STORAGE_LOAD_MEDIA, NULL, 
                      0, NULL, 0, &d, NULL);
      // PART B
      SetCursorPos( X, Y );
   }

Nearly, I tried that myself. I'll explain:

When the drive loads, this sets the mouse position, then it gives the user time to react by closing the window, before the drive loads again. You see? And yes, even giving this condition after the ejection still doesn't suffice.

I want them both to be running at the same time constantly.

On that note, is it possible to hide the command window? This would suffice...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.