The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: tekhead009 on April 29, 2005, 09:13:36 PM

Title: Device Arrival detection
Post by: tekhead009 on April 29, 2005, 09:13:36 PM
I'm struggling to create my first actually useful application in ASM. (Backstory incase you know an easier way) I wan't to enable autorun a memory device (USB key), but autorun.inf is only processed for ICON=; XP will not allow me to execute a program on the key. What I've decided to do is create a tiny program which sits and waits for a memory key to be inserted, so that the program can execute the autorun.

I have managed to patch together some C code that does the following:

1. My program detects a WM_DEVICECHANGE message
2. It checks to make sure it was a DBT_DEVICEARRIVAL message
3. Checks the lParam DEV_BROADCAST_HDR.dbch_devicetype to see if it was a volume
4. Checks the lParam DEV_BROADCAST_VOLUME.dbcv_unitmask to get the drive number
5. If the drive numnber is 1 (a:) it tries to execute a:\autorun.exe

I'm a worse C programmer than ASM (it's close though), so it works, but everything is hardcoded and there's a funkey bug where it tells me 'no disk is inserted into drive <blank>.' twice; then executes autorun - but only the first time after the program has been loaded, after that it's smooth sailing.

So off to ASM I go to create a better program. However, I can't get past step 3. WM_DEVICECHANGE is defined in windows.inc; I know that DBT_DEVICEARRIVAL is equ 8000h because MSDN says so, but I don't see dbch_devicetype defined as a value anywhere, so I can't check it.

I can inlclude dbt.h with C; but I didn't find any include files that contained these constants in MASM.

Are these values hidden anywhere I don't know of, on MSDN, or in an INCLUDE that evaded my search? I couldn't find them in the Win32 Programmers Reference either. Or am I missing something completely?
Title: Re: Device Arrival detection
Post by: Eóin on April 30, 2005, 12:06:48 AM
Someone just hasn't defined those structres yet. You could look them up in the Dbt.h and define them.
Title: Re: Device Arrival detection
Post by: tekhead009 on April 30, 2005, 05:36:04 AM
Oi, your right. I had opened them up before to see if I could do that, but I had opened them in notepad and they were not readable.
After trying a second time after your suggestion I opened them through my C IDE and I can now see them.
Why arn't they saved as plain ASCII text?

Blah. Sorry bout that.
Title: Re: Device Arrival detection
Post by: tekhead009 on April 30, 2005, 05:23:20 PM
I'm just going to do the entire file in one shot; but going through the contents of dbt.h and I've run into something that I don't get:


#if (_WIN32_WINDOWS >= 0x0410 || _WIN32_WINNT >= 0x0500)
#define DBT_DEVTYP_DEVICEINTERFACE 5
#define DBT_DEVTYP_HANDLE 6
#endif /* (_WIN32_WINDOWS >= 0x0410 || _WIN32_WINNT >= 0x0500) */


It looks like a conditional definition? Should I create the constants as they are, or is there a way of matching this in masm?
Title: Re: Device Arrival detection
Post by: sluggy on May 01, 2005, 12:51:48 AM
Those are compile time conditional definitions. They are setting those values according to what version of windows you are targetting your app for, you may find that earlier versions of windows do not have the functionality that those constants are part of.