Citrix WinFrame API SDK
How to detect WFAPI is installed on the system and functioning properly
Sample
# include <tchar.h>
# include <stdio.h>
# include "wfapi.h"
/*Change this to WFAPI for 32 bit*/
# define WFAPILIB _T("WFAPI64DLL")`
/* WFFreeMemory function pointer */
typedef VOID ( WINAPI *PFnWFFreeMemory) (PVOID);
/* WFSendMessage function pointer*/
typedef BOOL ( WINAPI *PFnWFSendMessage)
(IN HANDLE hServer,
IN DWORD SessionId,
IN LPWSTR pTitle,
IN DWORD TitleLength,
IN LPWSTR pMessage,
IN DWORD MessageLength,
IN DWORD Style,
IN DWORD Timeout,
OUT DWORD* pResponse,
IN BOOL bWait);
/* WFQuerySessionInformation function pointer*/
typedef BOOL ( WINAPI *PFnWFQuerySessionInformation)
(IN HANDLE hServer,
IN DWORD SessionId,
IN WF_INFO_CLASS WFInfoClass,
OUT LPWSTR* ppBuffer,
OUT DWORD* pBytesReturned);
/* WFEnumerateProcesses function pointer*/
typedef BOOL ( WINAPI *PFnWFEnumerateProcesses)
(IN HANDLE hServer,
IN DWORD Reserved,
IN DWORD Version,
OUT PWF_PROCESS_INFOW *ppProcessInfo,
OUT DWORD *pCount);
/* WFEnumerateSessions function pointer*/
typedef BOOL ( WINAPI *PFnWFEnumerateSessions)
(IN HANDLE hServer,
IN DWORD Reserved,
IN DWORD Version,
OUT PWF_SESSION_INFOW* ppSessionInfo,
OUT DWORD* pCount);
/*UNICODE version of method call : For ANSI replace W with A */
PFnWFSendMessage pFnWFSendMessage = NULL;
char aWFSendMessage[] = "WFSendMessageW";
PFnWFEnumerateSessions pFnWFEnumerateSessions = NULL;
char aWFEnumerateSessions[] = "WFEnumerateSessionsW";
PFnWFEnumerateProcesses pFnWFEnumerateProcesses = NULL;
char aWFEnumerateProcesses[] = "WFEnumerateProcessesW";
PFnWFQuerySessionInformation pFnWFQuerySessionInformation = NULL;
char aWFQuerySessionInformation[] = "WFQuerySessionInformationW";
PFnWFFreeMemory pFnWFFreeMemory = NULL;
char aWFFreeMemory[] = "WFFreeMemory";
VOID freeWFMemory(void * pVoid)
{
if (pVoid != NULL)
{
pFnWFFreeMemory(pVoid);
pVoid = NULL;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE dll;
DWORD sessionid = WF_CURRENT_SESSION;
LPWSTR pztitle =_T("WFAPI");
LPWSTR pzmessage =_T("WFAPI Test message");
DWORD resp = 0;
/* Trying to load WFAPI dll , expecting to have the library in system search path as set in environment variable ,you can also change this to a specific location */
dll = LoadLibrary(WFAPILIB);
if (dll == NULL )
{
_tprintf(_T("Could not locate WFAPI on the system...\n"));
return 0;
}
else
{
_tprintf(_T("Found WFAPI on the machine...\n"));
}
pFnWFSendMessage = (PFnWFSendMessage) GetProcAddress(dll,
aWFSendMessage);
pFnWFFreeMemory = (PFnWFFreeMemory) GetProcAddress(dll, aWFFreeMemory);
pFnWFEnumerateSessions = (PFnWFEnumerateSessions) GetProcAddress(dll,
aWFEnumerateSessions);
pFnWFEnumerateProcesses = (PFnWFEnumerateProcesses) GetProcAddress(dll,
aWFEnumerateProcesses);
pFnWFQuerySessionInformation = (PFnWFQuerySessionInformation)
GetProcAddress(dll, aWFQuerySessionInformation);
/* Checking for Non NULL function pointer */
if((pFnWFSendMessage != NULL) &&
(pFnWFFreeMemory != NULL) &&
(pFnWFEnumerateSessions != NULL) &&
(pFnWFEnumerateProcesses != NULL) &&
(pFnWFQuerySessionInformation != NULL))
{
/* Send message to current session and current server */
if(pFnWFSendMessage(WF_CURRENT_SERVER_HANDLE,
sessionid,
pztitle,
(_tcslen(_T("WFAPI")) + 1) *sizeof(TCHAR),pzmessage,
(_tcslen(_T("WFAPI Test message")) + 1) * sizeof(TCHAR),
MB_OK,
0 ,
&resp,
FALSE))
{
_tprintf(_T("Message could be send using WFAPI API\...\n"));
}
}
FreeLibrary(dll);
return 0;
}
<!--NeedCopy-->
How to detect WFAPI is installed on the system and functioning properly
In this article
Copied!
Failed!