From: Rich Y. Rich on
Hello--

The example code below calls GetCurrentHwProfile to determine whether a
computer is "dockable" or not (i.e. whether or not it's a laptop). According
to MSDN, "desktop systems that cannot be undocked" will always set the
DOCKINFO_DOCKED *and* the DOCKINFO_UNDOCKED flags in the struct that's
returned by this call
(http://msdn2.microsoft.com/en-us/library/ms724479.aspx).

The code below works well on my XP-based Dell Optiplex GX260 (i.e. the code
correctly determines that this computer is "Not Dockable" because both flags
are set). However upon installing Vista Business on this computer, this code
now states that this computer is a laptop (i.e. only the UNDOCKED flag is
set).

Q1: This is the *same computer*, and there's no new information on MDSN.
Could this be a bug in the Vista OS (or possibly, MSDN documentation)? If
it's not a bug, then how should I properly detect whether or not the computer
at hand is dockable?

Q2: When my computer had XP installed, the USER_SUPPLIED flag was set. With
Vista, this flag was not set. What does this flag mean? Could it explain
the difference in behavior? MSDN documentation falls short in the
explanation of this flag (see previously referenced URL).

Thank you,
Rich Y.
Austin, TX

int main (const int argc, const char* const * const argv) {
//----------------------------------------------------------------------
// Try to dynamically load DLL needed for GetCurrentHwProfileW.
//----------------------------------------------------------------------
if (HMODULE dll = ::LoadLibrary("ADVAPI32.DLL")) {
//------------------------------------------------------------------
// Try to get the function pointer for GetCurrentHwProfileW.
//------------------------------------------------------------------
typedef BOOL (WINAPI *GetHwProfileFn)(LPHW_PROFILE_INFOW);
if (GetHwProfileFn fn = (GetHwProfileFn)::GetProcAddress(dll,
"GetCurrentHwProfileW")) {
//--------------------------------------------------------------
// Get the current hardware profile if we can.
//--------------------------------------------------------------
HW_PROFILE_INFOW profile;
if ((fn)(&profile)) {
//----------------------------------------------------------
// Find if it's currently docked and/or currently undocked.
//----------------------------------------------------------
bool docked = (profile.dwDockInfo & DOCKINFO_DOCKED) != 0;
bool undocked = (profile.dwDockInfo & DOCKINFO_UNDOCKED) != 0;
bool userSupplied = (profile.dwDockInfo &
DOCKINFO_USER_SUPPLIED) != 0;
//----------------------------------------------------------
// Is this result "user supplied?"
//----------------------------------------------------------
if (userSupplied) {
MessageBox(NULL, "User Supplied", NULL, MB_OK);
}
//----------------------------------------------------------
// If docked XOR undocked, it's dockable.
//----------------------------------------------------------
if (docked != undocked) {
MessageBox(NULL, "Dockable", NULL, MB_OK);
}
//----------------------------------------------------------
// If docked AND undocked, it's not dockable (according
// to MSDN)
//----------------------------------------------------------
else if (docked && undocked) {
MessageBox(NULL, "Not Dockable", NULL, MB_OK);
}
//----------------------------------------------------------
// If not docked and not undocked, who knows.
//----------------------------------------------------------
else {
MessageBox(NULL, "Unexpected Result", NULL, MB_OK);
_ASSERT(false);
}
}
}
}
}
From: Pavel A. on
"Rich Y." wrote:
> Hello--
>
> The example code below calls GetCurrentHwProfile to determine whether a
> computer is "dockable" or not (i.e. whether or not it's a laptop). According
> to MSDN, "desktop systems that cannot be undocked" will always set the
> DOCKINFO_DOCKED *and* the DOCKINFO_UNDOCKED flags in the struct that's
> returned by this call
> (http://msdn2.microsoft.com/en-us/library/ms724479.aspx).
>
> The code below works well on my XP-based Dell Optiplex GX260 (i.e. the code
> correctly determines that this computer is "Not Dockable" because both flags
> are set). However upon installing Vista Business on this computer, this code
> now states that this computer is a laptop (i.e. only the UNDOCKED flag is
> set).
>
> Q1: This is the *same computer*, and there's no new information on MDSN.
> Could this be a bug in the Vista OS (or possibly, MSDN documentation)? If
> it's not a bug, then how should I properly detect whether or not the computer
> at hand is dockable?

AFAIK, impossible, until it actually gets docked, and a "docked"
profile has been created.

Also, Windows does not define laptop as system with docking capability.
For XP, a laptop is machine with a _long lasting_ battery.
Vista may also detect laptop by special fields in it's ACPI info.

> Q2: When my computer had XP installed, the USER_SUPPLIED flag was set. With
> Vista, this flag was not set. What does this flag mean?

Maybe it means that the profile is manually created.
Unlike XP, Vista does not seem to let users make profiles manually.

Regards,
--PA