My Device (WinCE/Pocket PC/Windows Mobile) placed in the dock and connected
to XP desktop through USB. ie, Activesync connection established.
When my application starts in the device, I want to disconnect ActiveSync
from my app (not manual removal of cable). When my app ends ActiveSync
connection should reestablished.
How I can connect/disconnect ActiveSync programmatically.
Thanks for your help in advance.
Regards,
NoushadAli
You can certainly use the IOCTL_UFN_CHANGE_CURRENT_CLIENT to
dynamically swap between a mass-storage profile and a serial
(Activesync) one, so I think therefore it should also be possible to
do the same to effectively enable/disable Activesync (by picking a
different client):
http://msdn.microsoft.com/en-us/library/ms895475.aspx
Something like this should work...
HANDLE hUSBFn;
UFN_CLIENT_INFO info;
DWORD dwBytes;
// Open the USB function driver
hUSBFn = CreateFile(USB_FUN_DEV, DEVACCESS_BUSNAMESPACE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(enableActiveSync)
{
// enable activesync
swprintf(info.szName, _T("Serial_Class"));
DeviceIoControl(hUSBFn, IOCTL_UFN_CHANGE_CURRENT_CLIENT,
info.szName, sizeof(info.szName), NULL, 0, &dwBytes, NULL))
}
else
{
// enable mass-storage, disable actviesync
swprintf(info.szName, _T("Mass_Storage_Class"));
DeviceIoControl(hUSBFn, IOCTL_UFN_CHANGE_CURRENT_CLIENT,
info.szName, sizeof(info.szName), NULL, 0, &dwBytes, NULL);
}
best regards,
Rik Attrill
These are all declared in is "usbfnioctl.h" (C:\WINCE600\PUBLIC\COMMON
\OAK\INC).
regards,
Rik
Below is the working code: (I have tested it on WM 5.0 and 6.1 device)
#include "winioctl.h"
#include "usbfnioctl.h"
#include "devload.h"
#define USB_FUN_DEV L"UFN1:"
void TogleActiveSync(bool bStatus)
{
HANDLE hUSBFn;
UFN_CLIENT_INFO info;
DWORD dwBytes;
// Open the USB function driver
hUSBFn = CreateFile(USB_FUN_DEV, DEVACCESS_BUSNAMESPACE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(Status)
{
// enable activesync
swprintf(info.szName, _T("Serial_Class"));
DeviceIoControl(hUSBFn, IOCTL_UFN_CHANGE_CURRENT_CLIENT, info.szName,
sizeof(info.szName), NULL, 0, &dwBytes, NULL);
}
else
{
// enable mass-storage, disable actviesync
swprintf(info.szName, _T("Mass_Storage_Class"));
DeviceIoControl(hUSBFn, IOCTL_UFN_CHANGE_CURRENT_CLIENT, info.szName,
sizeof(info.szName), NULL, 0, &dwBytes, NULL);
}
}
Regards,
Rahul
Once again Thanks.
Regards,
Noushad
>Hi,
>
>My Device (WinCE/Pocket PC/Windows Mobile) placed in the dock and connected
>to XP desktop through USB. ie, Activesync connection established.
>When my application starts in the device, I want to disconnect ActiveSync
>from my app (not manual removal of cable). When my app ends ActiveSync
>connection should reestablished.
>How I can connect/disconnect ActiveSync programmatically.
I admit I haven't checked in a while, but I'm quite sure repllog.exe
is "ActiveSync" on the device side. I _think_ you can stop it by
"running" it (use CreateProcess function), but I seem to stop it by
finding the window (use FindWindow with windowclassname ActiveSync and
then sending a WM_CLOSE message. I'm quite sure you can restart it by
running it without arguments. My uncertainty is because all this is
used in code I haven't touched in years, and I'm not in touch with all
the users (I'm pretty sure some still use the related feature, and
know I haven't received complaints about it).
>
>Thanks for your help in advance.
>
>Regards,
>NoushadAli
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com