How can i send content to the Windows SideShow simulator
Hi everybody:
I am a rookie ,i have just started to write a gadget,how can i send content to the Windows SideShow simulator?
HRESULT CAlarmContent::GetContent(
ISideShowCapabilities *pICapabilities,
DWORD* pdwSize,
BYTE** ppbData)
{
HRESULT hr = S_OK;
SYSTEMTIME sysTime;
WORD wHour;
WORD wMinute;
::GetLocalTime(&sysTime);
wHour=sysTime.wHour;
wMinute=sysTime.wMinute;
if (NULL == pdwSize || NULL == ppbData)
{
return E_INVALIDARG;
}
//
// For now, just use static content to send to the device.
// The string needs to be UTF-8 for Beta 1.
//
char* szXML = "<body><content id=\"1\" title=\"Alarm Clock Sample\"><txt align=\"c\" wrap=\"1\"><br/>Alarms can be set from the Alarm Clock Sample application on the Windows Desktop.</txt></content></body>";
//
// We need to CoTaskMemAlloc memory to return to the platform.
// Make sure the size includes the terminating NULL character of the string!
//
*pdwSize = (DWORD)strlen(szXML) + 1;
*ppbData = (BYTE*)::CoTaskMemAlloc(*pdwSize);
if (NULL != *ppbData)
{
//
// Use the safe string copy function to ensure
// we don't overwrite the bounds of the allocated
// buffer.
//
hr = StringCchCopyA((LPSTR)*ppbData, *pdwSize, szXML);
}
else
{
hr = E_OUTOFMEMORY;
}
return hr;
}
I copy the code from the msdn,but it display " For now, just use static content to send to the device",i want to display the time in dynamic,how can i do?
Nike
[1868 byte] By [
Nike] at [2008-2-4]
Hi Nike,
The code snippet you refer to above is a callback which provides content to the SideShow platform. In order to send the content to the device, you need to create an instance of your object which implements the ISideShowContent interface, and then call ISideShowContentManager::Add() with the pointer to that interface.
To have the time displayed dynamically, you can update the ISideShowContent::GetContent() method to include the current time as part of the XML string (I would use StringCchPrintfA(), for example). Then, you would repeatedly call ISideShowContentManager::Add() on a timer to re-send the updated content at the interval you require (1 second, for example).
Hope that helps,
Dan
Hi Dan:
I want to write a gadget ,can you recommend some weds or books?
THKS!
Dan,
SYSTEMTIME alarmTime;
::GetLocalTime(&alarmTime);
char* szXML = "<body><content id=\"1\" title=\"Alarm Clock Sample\"><txt align=\"c\" wrap=\"1\"><br/>Alarms can be set from the Alarm Clock Sample application on the Windows Desktop.</txt></content></body>";
hr = StringCchCopyA((LPSTR)*ppbData, *pdwSize, szXML);
I can get the system time by the GetLocalTime,but how can i change the system time to the XML string?
Thanks!
Nike
Nike,
You can use a function such as StringCchPrintf() to format the time into an XML string.
Dan
Hi Dan:
I wirte the codes to the registry as follows ,but i can not find the gadget in the Windows SideShow of the Control Panel ,what is worry with this ? Can you help me?
LPBYTE CString_To_LPBYTE(CString str)
{
LPBYTE lpb=new BYTE[str.GetLength()];
for(int i=0;i<str.GetLength();i++)
{
lpb
=(BYTE)str
;
//lpb[i+1]='\0';
}
lpb[str.GetLength()]=0;
return lpb;
}
void CbbDlg:
nBnClickedButton1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
char *sclass="";
DWORD nbf=0;
HKEY hKEY;
LPCTSTR data_Set=L"Software\\Microsoft\\SideShow\\Gadgets\\{1F11B914-F461-4785-877C-482AB481CF7A}";
long ret0=(::RegCreateKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,(LPWSTR)sclass,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKEY,&nbf));
if(ret0!=ERROR_SUCCESS)
{
return;
}
else
{
CString m_str;
m_str=L"Nike";
LPBYTE owner_Set=CString_To_LPBYTE(m_str);
DWORD type_1=REG_SZ;
DWORD cbData_1=m_str.GetLength()+1;
long ret1=::RegSetValueExA(hKEY,(LPCSTR)"FriendlyName",NULL,type_1,owner_Set,cbData_1);
if(ret1!=ERROR_SUCCESS)
{
return;
}
CString m_Endpoint;
m_Endpoint=L"{A9A5353F-2D4B-47ce-93EE-759F3A7DDA4F}";
LPBYTE owner_Set2=CString_To_LPBYTE(m_Endpoint);
DWORD type_2=REG_MULTI_SZ;
DWORD cbData_2=m_Endpoint.GetLength()+1;
long ret2=::RegSetValueExA(hKEY,(LPCSTR)"Endpoints",NULL,type_2,owner_Set2,cbData_2);
if(ret2!=ERROR_SUCCESS)
{
return;
}
}
::RegCloseKey(hKEY);
UpdateData(false);
}
Dan
I understand the how to wirte the codes to the registry ,i must use the .reg file.
Hi Dan:
I have a device that can receive data but it is not a SideShow device,how can i do to change the deivce to the SideShow device?
I must write a driver?
If i must write a driver,can you tell me some information?
Thanks!
Nike,
Glad you got the registry keys working. It is possible to do it from code as well, but I do not have any examples. In our samples, we typically perform the registration through a .REG file, or as part of the gadget installer (MSI) via the registry table.
To make a device SideShow-compatible, you must have an appropriate driver that implements the SideShow interfaces. This is described in detail in the Windows Driver Kit (WDK), as well as in numerous other posts in this forum.
Dan