Merge branch 'fdsapi' of https://github.com/awakecoding/FreeRDP into awakecoding

This commit is contained in:
Mike McDonald 2014-04-11 10:13:27 -04:00
commit 38c7a38141
22 changed files with 2302 additions and 12 deletions

3
.gitignore vendored
View File

@ -42,6 +42,9 @@ include/freerdp/version.h
*.cproject
*.settings
nbproject/
compile_commands.json
# .rdp files
*.rdp
*.RDP

78
winpr/include/winpr/ini.h Normal file
View File

@ -0,0 +1,78 @@
/**
* WinPR: Windows Portable Runtime
* .ini config file
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WINPR_UTILS_INI_H
#define WINPR_UTILS_INI_H
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
struct _wIniFileKey
{
char* name;
char* value;
};
typedef struct _wIniFileKey wIniFileKey;
struct _wIniFileSection
{
char* name;
int nKeys;
int cKeys;
wIniFileKey** keys;
};
typedef struct _wIniFileSection wIniFileSection;
struct _wIniFile
{
FILE* fp;
char* line;
char* nextLine;
int lineLength;
char* buffer;
char* filename;
BOOL readOnly;
int nSections;
int cSections;
wIniFileSection** sections;
};
typedef struct _wIniFile wIniFile;
#ifdef __cplusplus
extern "C" {
#endif
WINPR_API int IniFile_Parse(wIniFile* ini, const char* filename);
WINPR_API int IniFile_ParseString(wIniFile* ini, const char* iniString);
WINPR_API char** IniFile_GetSectionNames(wIniFile* ini, int* count);
WINPR_API char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count);
WINPR_API char* IniFile_GetKeyValueString(wIniFile* ini, const char* section, const char* key);
WINPR_API UINT32 IniFile_GetKeyValueInt(wIniFile* ini, const char* section, const char* key);
WINPR_API wIniFile* IniFile_New();
WINPR_API void IniFile_Free(wIniFile* ini);
#ifdef __cplusplus
}
#endif
#endif /* WINPR_UTILS_INI_H */

View File

@ -46,16 +46,21 @@ WINPR_API HMODULE LoadLibraryW(LPCWSTR lpLibFileName);
WINPR_API HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
WINPR_API HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
WINPR_API HMODULE GetModuleHandleA(LPCSTR lpModuleName);
WINPR_API HMODULE GetModuleHandleW(LPCWSTR lpModuleName);
WINPR_API DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
WINPR_API DWORD GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#define GetModuleHandle GetModuleHandleW
#define GetModuleFileName GetModuleFileNameW
#else
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#define GetModuleHandle GetModuleHandleA
#define GetModuleFileName GetModuleFileNameA
#endif

570
winpr/include/winpr/wnd.h Normal file
View File

@ -0,0 +1,570 @@
/**
* WinPR: Windows Portable Runtime
* Window Notification System
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WINPR_WND_H
#define WINPR_WND_H
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <winpr/windows.h>
#ifndef _WIN32
#define WM_NULL 0x0000
#define WM_CREATE 0x0001
#define WM_DESTROY 0x0002
#define WM_MOVE 0x0003
#define WM_SIZE 0x0005
#define WM_ACTIVATE 0x0006
#define WM_SETFOCUS 0x0007
#define WM_KILLFOCUS 0x0008
#define WM_ENABLE 0x000A
#define WM_SETREDRAW 0x000B
#define WM_SETTEXT 0x000C
#define WM_GETTEXT 0x000D
#define WM_GETTEXTLENGTH 0x000E
#define WM_PAINT 0x000F
#define WM_CLOSE 0x0010
#define WM_QUERYENDSESSION 0x0011
#define WM_QUERYOPEN 0x0013
#define WM_ENDSESSION 0x0016
#define WM_QUIT 0x0012
#define WM_ERASEBKGND 0x0014
#define WM_SYSCOLORCHANGE 0x0015
#define WM_SHOWWINDOW 0x0018
#define WM_WININICHANGE 0x001A
#define WM_SETTINGCHANGE 0x001A
#define WM_DEVMODECHANGE 0x001B
#define WM_ACTIVATEAPP 0x001C
#define WM_FONTCHANGE 0x001D
#define WM_TIMECHANGE 0x001E
#define WM_CANCELMODE 0x001F
#define WM_SETCURSOR 0x0020
#define WM_MOUSEACTIVATE 0x0021
#define WM_CHILDACTIVATE 0x0022
#define WM_QUEUESYNC 0x0023
#define WM_GETMINMAXINFO 0x0024
#define WM_PAINTICON 0x0026
#define WM_ICONERASEBKGND 0x0027
#define WM_NEXTDLGCTL 0x0028
#define WM_SPOOLERSTATUS 0x002A
#define WM_DRAWITEM 0x002B
#define WM_MEASUREITEM 0x002C
#define WM_DELETEITEM 0x002D
#define WM_VKEYTOITEM 0x002E
#define WM_CHARTOITEM 0x002F
#define WM_SETFONT 0x0030
#define WM_GETFONT 0x0031
#define WM_SETHOTKEY 0x0032
#define WM_GETHOTKEY 0x0033
#define WM_QUERYDRAGICON 0x0037
#define WM_COMPAREITEM 0x0039
#define WM_GETOBJECT 0x003D
#define WM_COMPACTING 0x0041
#define WM_COMMNOTIFY 0x0044
#define WM_WINDOWPOSCHANGING 0x0046
#define WM_WINDOWPOSCHANGED 0x0047
#define WM_POWER 0x0048
#define WM_COPYDATA 0x004A
#define WM_CANCELJOURNAL 0x004B
#define WM_NOTIFY 0x004E
#define WM_INPUTLANGCHANGEREQUEST 0x0050
#define WM_INPUTLANGCHANGE 0x0051
#define WM_TCARD 0x0052
#define WM_HELP 0x0053
#define WM_USERCHANGED 0x0054
#define WM_NOTIFYFORMAT 0x0055
#define WM_CONTEXTMENU 0x007B
#define WM_STYLECHANGING 0x007C
#define WM_STYLECHANGED 0x007D
#define WM_DISPLAYCHANGE 0x007E
#define WM_GETICON 0x007F
#define WM_SETICON 0x0080
#define WM_NCCREATE 0x0081
#define WM_NCDESTROY 0x0082
#define WM_NCCALCSIZE 0x0083
#define WM_NCHITTEST 0x0084
#define WM_NCPAINT 0x0085
#define WM_NCACTIVATE 0x0086
#define WM_GETDLGCODE 0x0087
#define WM_SYNCPAINT 0x0088
#define WM_NCMOUSEMOVE 0x00A0
#define WM_NCLBUTTONDOWN 0x00A1
#define WM_NCLBUTTONUP 0x00A2
#define WM_NCLBUTTONDBLCLK 0x00A3
#define WM_NCRBUTTONDOWN 0x00A4
#define WM_NCRBUTTONUP 0x00A5
#define WM_NCRBUTTONDBLCLK 0x00A6
#define WM_NCMBUTTONDOWN 0x00A7
#define WM_NCMBUTTONUP 0x00A8
#define WM_NCMBUTTONDBLCLK 0x00A9
#define WM_NCXBUTTONDOWN 0x00AB
#define WM_NCXBUTTONUP 0x00AC
#define WM_NCXBUTTONDBLCLK 0x00AD
#define WM_INPUT_DEVICE_CHANGE 0x00FE
#define WM_INPUT 0x00FF
#define WM_KEYFIRST 0x0100
#define WM_KEYDOWN 0x0100
#define WM_KEYUP 0x0101
#define WM_CHAR 0x0102
#define WM_DEADCHAR 0x0103
#define WM_SYSKEYDOWN 0x0104
#define WM_SYSKEYUP 0x0105
#define WM_SYSCHAR 0x0106
#define WM_SYSDEADCHAR 0x0107
#define WM_UNICHAR 0x0109
#define WM_KEYLAST 0x0109
#define WM_IME_STARTCOMPOSITION 0x010D
#define WM_IME_ENDCOMPOSITION 0x010E
#define WM_IME_COMPOSITION 0x010F
#define WM_IME_KEYLAST 0x010F
#define WM_INITDIALOG 0x0110
#define WM_COMMAND 0x0111
#define WM_SYSCOMMAND 0x0112
#define WM_TIMER 0x0113
#define WM_HSCROLL 0x0114
#define WM_VSCROLL 0x0115
#define WM_INITMENU 0x0116
#define WM_INITMENUPOPUP 0x0117
#define WM_GESTURE 0x0119
#define WM_GESTURENOTIFY 0x011A
#define WM_MENUSELECT 0x011F
#define WM_MENUCHAR 0x0120
#define WM_ENTERIDLE 0x0121
#define WM_MENURBUTTONUP 0x0122
#define WM_MENUDRAG 0x0123
#define WM_MENUGETOBJECT 0x0124
#define WM_UNINITMENUPOPUP 0x0125
#define WM_MENUCOMMAND 0x0126
#define WM_CHANGEUISTATE 0x0127
#define WM_UPDATEUISTATE 0x0128
#define WM_QUERYUISTATE 0x0129
#define WM_CTLCOLORMSGBOX 0x0132
#define WM_CTLCOLOREDIT 0x0133
#define WM_CTLCOLORLISTBOX 0x0134
#define WM_CTLCOLORBTN 0x0135
#define WM_CTLCOLORDLG 0x0136
#define WM_CTLCOLORSCROLLBAR 0x0137
#define WM_CTLCOLORSTATIC 0x0138
#define WM_MOUSEFIRST 0x0200
#define WM_MOUSEMOVE 0x0200
#define WM_LBUTTONDOWN 0x0201
#define WM_LBUTTONUP 0x0202
#define WM_LBUTTONDBLCLK 0x0203
#define WM_RBUTTONDOWN 0x0204
#define WM_RBUTTONUP 0x0205
#define WM_RBUTTONDBLCLK 0x0206
#define WM_MBUTTONDOWN 0x0207
#define WM_MBUTTONUP 0x0208
#define WM_MBUTTONDBLCLK 0x0209
#define WM_MOUSEWHEEL 0x020A
#define WM_XBUTTONDOWN 0x020B
#define WM_XBUTTONUP 0x020C
#define WM_XBUTTONDBLCLK 0x020D
#define WM_MOUSEHWHEEL 0x020E
#define WM_MOUSELAST 0x020E
#define WM_PARENTNOTIFY 0x0210
#define WM_ENTERMENULOOP 0x0211
#define WM_EXITMENULOOP 0x0212
#define WM_NEXTMENU 0x0213
#define WM_SIZING 0x0214
#define WM_CAPTURECHANGED 0x0215
#define WM_MOVING 0x0216
#define WM_POWERBROADCAST 0x0218
#define WM_DEVICECHANGE 0x0219
#define WM_MDICREATE 0x0220
#define WM_MDIDESTROY 0x0221
#define WM_MDIACTIVATE 0x0222
#define WM_MDIRESTORE 0x0223
#define WM_MDINEXT 0x0224
#define WM_MDIMAXIMIZE 0x0225
#define WM_MDITILE 0x0226
#define WM_MDICASCADE 0x0227
#define WM_MDIICONARRANGE 0x0228
#define WM_MDIGETACTIVE 0x0229
#define WM_MDISETMENU 0x0230
#define WM_ENTERSIZEMOVE 0x0231
#define WM_EXITSIZEMOVE 0x0232
#define WM_DROPFILES 0x0233
#define WM_MDIREFRESHMENU 0x0234
#define WM_POINTERDEVICECHANGE 0x0238
#define WM_POINTERDEVICEINRANGE 0x0239
#define WM_POINTERDEVICEOUTOFRANGE 0x023A
#define WM_TOUCH 0x0240
#define WM_NCPOINTERUPDATE 0x0241
#define WM_NCPOINTERDOWN 0x0242
#define WM_NCPOINTERUP 0x0243
#define WM_POINTERUPDATE 0x0245
#define WM_POINTERDOWN 0x0246
#define WM_POINTERUP 0x0247
#define WM_POINTERENTER 0x0249
#define WM_POINTERLEAVE 0x024A
#define WM_POINTERACTIVATE 0x024B
#define WM_POINTERCAPTURECHANGED 0x024C
#define WM_TOUCHHITTESTING 0x024D
#define WM_POINTERWHEEL 0x024E
#define WM_POINTERHWHEEL 0x024F
#define WM_IME_SETCONTEXT 0x0281
#define WM_IME_NOTIFY 0x0282
#define WM_IME_CONTROL 0x0283
#define WM_IME_COMPOSITIONFULL 0x0284
#define WM_IME_SELECT 0x0285
#define WM_IME_CHAR 0x0286
#define WM_IME_REQUEST 0x0288
#define WM_IME_KEYDOWN 0x0290
#define WM_IME_KEYUP 0x0291
#define WM_MOUSEHOVER 0x02A1
#define WM_MOUSELEAVE 0x02A3
#define WM_NCMOUSEHOVER 0x02A0
#define WM_NCMOUSELEAVE 0x02A2
#define WM_WTSSESSION_CHANGE 0x02B1
#define WM_TABLET_FIRST 0x02c0
#define WM_TABLET_LAST 0x02df
#define WM_CUT 0x0300
#define WM_COPY 0x0301
#define WM_PASTE 0x0302
#define WM_CLEAR 0x0303
#define WM_UNDO 0x0304
#define WM_RENDERFORMAT 0x0305
#define WM_RENDERALLFORMATS 0x0306
#define WM_DESTROYCLIPBOARD 0x0307
#define WM_DRAWCLIPBOARD 0x0308
#define WM_PAINTCLIPBOARD 0x0309
#define WM_VSCROLLCLIPBOARD 0x030A
#define WM_SIZECLIPBOARD 0x030B
#define WM_ASKCBFORMATNAME 0x030C
#define WM_CHANGECBCHAIN 0x030D
#define WM_HSCROLLCLIPBOARD 0x030E
#define WM_QUERYNEWPALETTE 0x030F
#define WM_PALETTEISCHANGING 0x0310
#define WM_PALETTECHANGED 0x0311
#define WM_HOTKEY 0x0312
#define WM_PRINT 0x0317
#define WM_PRINTCLIENT 0x0318
#define WM_APPCOMMAND 0x0319
#define WM_THEMECHANGED 0x031A
#define WM_CLIPBOARDUPDATE 0x031D
#define WM_DWMCOMPOSITIONCHANGED 0x031E
#define WM_DWMNCRENDERINGCHANGED 0x031F
#define WM_DWMCOLORIZATIONCOLORCHANGED 0x0320
#define WM_DWMWINDOWMAXIMIZEDCHANGE 0x0321
#define WM_DWMSENDICONICTHUMBNAIL 0x0323
#define WM_DWMSENDICONICLIVEPREVIEWBITMAP 0x0326
#define WM_GETTITLEBARINFOEX 0x033F
#define WM_HANDHELDFIRST 0x0358
#define WM_HANDHELDLAST 0x035F
#define WM_AFXFIRST 0x0360
#define WM_AFXLAST 0x037F
#define WM_PENWINFIRST 0x0380
#define WM_PENWINLAST 0x038F
#define WM_APP 0x8000
#define WM_USER 0x0400
#define HWND_BROADCAST ((HWND)0xFFFF)
#define HWND_MESSAGE ((HWND)-3)
#define HWND_DESKTOP ((HWND)0)
#define HWND_TOP ((HWND)0)
#define HWND_BOTTOM ((HWND)1)
#define HWND_TOPMOST ((HWND)-1)
#define HWND_NOTOPMOST ((HWND)-2)
typedef WORD ATOM;
typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;
typedef FARPROC SENDASYNCPROC;
typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
typedef HANDLE HICON;
typedef HANDLE HCURSOR;
typedef HANDLE HBRUSH;
typedef HANDLE HMENU;
typedef struct tagWNDCLASSA
{
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCSTR lpszMenuName;
LPCSTR lpszClassName;
} WNDCLASSA, *PWNDCLASSA, NEAR *NPWNDCLASSA, FAR *LPWNDCLASSA;
typedef struct tagWNDCLASSW
{
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCWSTR lpszMenuName;
LPCWSTR lpszClassName;
} WNDCLASSW, *PWNDCLASSW, NEAR *NPWNDCLASSW, FAR *LPWNDCLASSW;
typedef struct tagWNDCLASSEXA
{
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCSTR lpszMenuName;
LPCSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEXA, *PWNDCLASSEXA, NEAR *NPWNDCLASSEXA, FAR *LPWNDCLASSEXA;
typedef struct tagWNDCLASSEXW
{
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCWSTR lpszMenuName;
LPCWSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEXW, *PWNDCLASSEXW, NEAR *NPWNDCLASSEXW, FAR *LPWNDCLASSEXW;
#ifdef UNICODE
typedef WNDCLASSW WNDCLASS;
typedef PWNDCLASSW PWNDCLASS;
typedef NPWNDCLASSW NPWNDCLASS;
typedef LPWNDCLASSW LPWNDCLASS;
typedef WNDCLASSEXW WNDCLASSEX;
typedef PWNDCLASSEXW PWNDCLASSEX;
typedef NPWNDCLASSEXW NPWNDCLASSEX;
typedef LPWNDCLASSEXW LPWNDCLASSEX;
#else
typedef WNDCLASSA WNDCLASS;
typedef PWNDCLASSA PWNDCLASS;
typedef NPWNDCLASSA NPWNDCLASS;
typedef LPWNDCLASSA LPWNDCLASS;
typedef WNDCLASSEXA WNDCLASSEX;
typedef PWNDCLASSEXA PWNDCLASSEX;
typedef NPWNDCLASSEXA NPWNDCLASSEX;
typedef LPWNDCLASSEXA LPWNDCLASSEX;
#endif
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;
typedef struct tagMSG
{
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG, *PMSG, NEAR *NPMSG, FAR *LPMSG;
typedef struct tagCOPYDATASTRUCT
{
ULONG_PTR dwData;
DWORD cbData;
PVOID lpData;
} COPYDATASTRUCT, *PCOPYDATASTRUCT;
typedef struct tagWTSSESSION_NOTIFICATION
{
DWORD cbSize;
DWORD dwSessionId;
} WTSSESSION_NOTIFICATION, *PWTSSESSION_NOTIFICATION;
#define WTS_CONSOLE_CONNECT 0x1
#define WTS_CONSOLE_DISCONNECT 0x2
#define WTS_REMOTE_CONNECT 0x3
#define WTS_REMOTE_DISCONNECT 0x4
#define WTS_SESSION_LOGON 0x5
#define WTS_SESSION_LOGOFF 0x6
#define WTS_SESSION_LOCK 0x7
#define WTS_SESSION_UNLOCK 0x8
#define WTS_SESSION_REMOTE_CONTROL 0x9
#define WTS_SESSION_CREATE 0xA
#define WTS_SESSION_TERMINATE 0xB
#ifdef __cplusplus
extern "C" {
#endif
WINPR_API WORD WINAPI GetWindowWord(HWND hWnd, int nIndex);
WINPR_API WORD WINAPI SetWindowWord(HWND hWnd, int nIndex, WORD wNewWord);
WINPR_API LONG WINAPI GetWindowLongA(HWND hWnd, int nIndex);
WINPR_API LONG WINAPI GetWindowLongW(HWND hWnd, int nIndex);
WINPR_API LONG WINAPI SetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong);
WINPR_API LONG WINAPI SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
WINPR_API LONG_PTR WINAPI GetWindowLongPtrA(HWND hWnd, int nIndex);
WINPR_API LONG_PTR WINAPI GetWindowLongPtrW(HWND hWnd, int nIndex);
WINPR_API LONG_PTR WINAPI SetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
WINPR_API LONG_PTR WINAPI SetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
WINPR_API BOOL WINAPI DestroyWindow(HWND hWnd);
WINPR_API VOID WINAPI PostQuitMessage(int nExitCode);
WINPR_API ATOM WINAPI RegisterClassA(CONST WNDCLASSA* lpWndClass);
WINPR_API ATOM WINAPI RegisterClassW(CONST WNDCLASSW* lpWndClass);
WINPR_API ATOM WINAPI RegisterClassExA(CONST WNDCLASSEXA* lpwcx);
WINPR_API ATOM WINAPI RegisterClassExW(CONST WNDCLASSEXW* lpwcx);
WINPR_API BOOL WINAPI UnregisterClassA(LPCSTR lpClassName, HINSTANCE hInstance);
WINPR_API BOOL WINAPI UnregisterClassW(LPCWSTR lpClassName, HINSTANCE hInstance);
WINPR_API HWND WINAPI CreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName,
LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
WINPR_API HWND WINAPI CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) \
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) \
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
WINPR_API HWND WINAPI FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName);
WINPR_API HWND WINAPI FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName);
WINPR_API HWND WINAPI FindWindowExA(HWND hWndParent, HWND hWndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow);
WINPR_API HWND WINAPI FindWindowExW(HWND hWndParent, HWND hWndChildAfter, LPCWSTR lpszClass, LPCWSTR lpszWindow);
WINPR_API BOOL WINAPI GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
WINPR_API BOOL WINAPI GetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
WINPR_API DWORD WINAPI GetMessagePos(VOID);
WINPR_API LONG WINAPI GetMessageTime(VOID);
WINPR_API LPARAM WINAPI GetMessageExtraInfo(VOID);
WINPR_API LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam);
WINPR_API BOOL WINAPI SetMessageQueue(int cMessagesMax);
WINPR_API LRESULT WINAPI SendMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API LRESULT WINAPI SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API LRESULT WINAPI SendMessageTimeoutA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult);
WINPR_API LRESULT WINAPI SendMessageTimeoutW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult);
WINPR_API BOOL WINAPI SendNotifyMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API BOOL WINAPI SendNotifyMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API BOOL WINAPI SendMessageCallbackA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData);
WINPR_API BOOL WINAPI SendMessageCallbackW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData);
WINPR_API BOOL WINAPI TranslateMessage(CONST MSG* lpMsg);
WINPR_API LRESULT WINAPI DispatchMessageA(CONST MSG* lpMsg);
WINPR_API LRESULT WINAPI DispatchMessageW(CONST MSG* lpMsg);
WINPR_API BOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
WINPR_API BOOL WINAPI PeekMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
WINPR_API BOOL WINAPI ReplyMessage(LRESULT lResult);
WINPR_API BOOL WINAPI WaitMessage(VOID);
WINPR_API LRESULT WINAPI CallWindowProcA(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API LRESULT WINAPI CallWindowProcW(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API LRESULT WINAPI DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WINPR_API LRESULT WINAPI DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
#ifdef UNICODE
#define GetWindowLong GetWindowLongW
#define SetWindowLong SetWindowLongW
#define GetWindowLongPtr GetWindowLongPtrW
#define SetWindowLongPtr SetWindowLongPtrW
#define RegisterClass RegisterClassW
#define RegisterClassEx RegisterClassExW
#define UnregisterClass UnregisterClassW
#define CreateWindow CreateWindowW
#define CreateWindowEx CreateWindowExW
#define FindWindow FindWindowW
#define FindWindowEx FindWindowExW
#define GetMessage GetMessageW
#define SendMessage SendMessageW
#define SendMessageTimeout SendMessageTimeoutW
#define SendNotifyMessage SendNotifyMessageW
#define SendMessageCallback SendMessageCallbackW
#define DispatchMessage DispatchMessageW
#define PeekMessage PeekMessageW
#define CallWindowProc CallWindowProcW
#define DefWindowProc DefWindowProcW
#else
#define GetWindowLong GetWindowLongA
#define SetWindowLong SetWindowLongA
#define GetWindowLongPtr GetWindowLongPtrA
#define SetWindowLongPtr SetWindowLongPtrA
#define RegisterClass RegisterClassA
#define RegisterClassEx RegisterClassExA
#define UnregisterClass UnregisterClassA
#define CreateWindow CreateWindowA
#define CreateWindowEx CreateWindowExA
#define FindWindow FindWindowA
#define FindWindowEx FindWindowExA
#define GetMessage GetMessageA
#define SendMessage SendMessageA
#define SendMessageTimeout SendMessageTimeoutA
#define SendNotifyMessage SendNotifyMessageA
#define SendMessageCallback SendMessageCallbackA
#define DispatchMessage DispatchMessageA
#define PeekMessage PeekMessageA
#define CallWindowProc CallWindowProcA
#define DefWindowProc DefWindowProcA
#endif
#ifdef __cplusplus
}
#endif
#endif
#endif /* WINPR_WND_H */

View File

@ -41,6 +41,14 @@
#define WINAPI
#define CDECL
#ifndef FAR
#define FAR
#endif
#ifndef NEAR
#define NEAR
#endif
#define __int8 char
#define __int16 short
#define __int32 int
@ -135,7 +143,7 @@ typedef unsigned long ULONG, *PULONG;
typedef ULONG HRESULT;
typedef ULONG SCODE;
typedef ULONG_PTR DWORD_PTR;
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
typedef ULONG_PTR SIZE_T;
typedef unsigned int ULONG32;
typedef unsigned __int64 ULONG64;

View File

@ -156,6 +156,16 @@ BOOL FreeLibrary(HMODULE hLibModule)
return TRUE;
}
HMODULE GetModuleHandleA(LPCSTR lpModuleName)
{
return NULL;
}
HMODULE GetModuleHandleW(LPCWSTR lpModuleName)
{
return NULL;
}
/**
* GetModuleFileName:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197/

View File

@ -75,6 +75,7 @@ set(${MODULE_PREFIX}_WLOG_SRCS
wlog/ConsoleAppender.h)
set(${MODULE_PREFIX}_SRCS
ini.c
sam.c
ntlm.c
print.c

492
winpr/libwinpr/utils/ini.c Normal file
View File

@ -0,0 +1,492 @@
/**
* WinPR: Windows Portable Runtime
* .ini config file
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/ini.h>
int IniFile_Load_String(wIniFile* ini, const char* iniString)
{
long int fileSize;
ini->line = NULL;
ini->nextLine = NULL;
ini->buffer = NULL;
fileSize = strlen(iniString);
if (fileSize < 1)
return -1;
ini->buffer = (char*) malloc(fileSize + 2);
CopyMemory(ini->buffer, iniString, fileSize);
ini->buffer[fileSize] = '\n';
ini->buffer[fileSize + 1] = '\0';
ini->nextLine = strtok(ini->buffer, "\n");
return 1;
}
int IniFile_Load_File(wIniFile* ini, const char* filename)
{
long int fileSize;
if (ini->readOnly)
{
ini->fp = fopen(filename, "r");
}
else
{
ini->fp = fopen(filename, "r+");
if (!ini->fp)
ini->fp = fopen(filename, "w+");
}
if (!ini->fp)
return -1;
fseek(ini->fp, 0, SEEK_END);
fileSize = ftell(ini->fp);
fseek(ini->fp, 0, SEEK_SET);
ini->line = NULL;
ini->nextLine = NULL;
ini->buffer = NULL;
if (fileSize < 1)
return -1;
ini->buffer = (char*) malloc(fileSize + 2);
if (fread(ini->buffer, fileSize, 1, ini->fp) != 1)
{
free(ini->buffer);
ini->buffer = NULL;
return -1;
}
ini->buffer[fileSize] = '\n';
ini->buffer[fileSize + 1] = '\0';
ini->nextLine = strtok(ini->buffer, "\n");
return 1;
}
void IniFile_Load_Finish(wIniFile* ini)
{
if (!ini)
return;
if (ini->buffer)
{
free(ini->buffer);
ini->buffer = NULL;
}
}
BOOL IniFile_Load_HasNextLine(wIniFile* ini)
{
if (!ini)
return FALSE;
return (ini->nextLine) ? TRUE : FALSE;
}
char* IniFile_Load_GetNextLine(wIniFile* ini)
{
if (!ini)
return NULL;
ini->line = ini->nextLine;
ini->nextLine = strtok(NULL, "\n");
ini->lineLength = strlen(ini->line);
return ini->line;
}
wIniFileKey* IniFile_Key_New(const char* name, const char* value)
{
wIniFileKey* key = malloc(sizeof(wIniFileKey));
if (key)
{
key->name = _strdup(name);
key->value = _strdup(value);
}
return key;
}
void IniFile_Key_Free(wIniFileKey* key)
{
if (key)
{
free(key->name);
free(key->value);
}
}
wIniFileSection* IniFile_Section_New(const char* name)
{
wIniFileSection* section = malloc(sizeof(wIniFileSection));
section->name = _strdup(name);
section->nKeys = 0;
section->cKeys = 64;
section->keys = (wIniFileKey**) malloc(sizeof(wIniFileKey*) * section->cKeys);
return section;
}
void IniFile_Section_Free(wIniFileSection* section)
{
if (section)
{
free(section);
}
}
int IniFile_AddSection(wIniFile* ini, const char* name)
{
if ((ini->nSections + 1) >= (ini->cSections))
{
ini->cSections *= 2;
ini->sections = (wIniFileSection**) realloc(ini->sections, sizeof(wIniFileSection*) * ini->cSections);
}
ini->sections[ini->nSections] = IniFile_Section_New(name);
ini->nSections++;
return 1;
}
int IniFile_AddKey(wIniFile* ini, wIniFileSection* section, const char* name, const char* value)
{
if (!section)
return -1;
if ((section->nKeys + 1) >= (section->cKeys))
{
section->cKeys *= 2;
section->keys = (wIniFileKey**) realloc(section->keys, sizeof(wIniFileKey*) * section->cKeys);
}
section->keys[section->nKeys] = IniFile_Key_New(name, value);
section->nKeys++;
return 1;
}
int IniFile_Load(wIniFile* ini)
{
char* line;
char* name;
char* value;
char* separator;
char *beg, *end;
wIniFileKey* key = NULL;
wIniFileSection* section = NULL;
while (IniFile_Load_HasNextLine(ini))
{
line = IniFile_Load_GetNextLine(ini);
if (line[0] == ';')
continue;
if (line[0] == '[')
{
beg = &line[1];
end = strchr(line, ']');
if (!end)
return -1;
*end = '\0';
IniFile_AddSection(ini, beg);
section = ini->sections[ini->nSections - 1];
}
else
{
separator = strchr(line, '=');
end = separator;
while ((&end[-1] > line) && ((end[-1] == ' ') || (end[-1] == '\t')))
end--;
*end = '\0';
name = line;
beg = separator + 1;
while (*beg && ((*beg == ' ') || (*beg == '\t')))
beg++;
if (*beg == '"')
beg++;
end = &line[ini->lineLength];
while ((end > beg) && ((end[-1] == ' ') || (end[-1] == '\t')))
end--;
if (end[-1] == '"')
end[-1] = '\0';
value = beg;
IniFile_AddKey(ini, section, name, value);
key = section->keys[section->nKeys - 1];
}
}
IniFile_Load_Finish(ini);
return 1;
}
int IniFile_ParseString(wIniFile* ini, const char* iniString)
{
int status;
ini->readOnly = TRUE;
ini->filename = NULL;
status = IniFile_Load_String(ini, iniString);
if (status < 0)
return status;
status = IniFile_Load(ini);
return status;
}
int IniFile_Parse(wIniFile* ini, const char* filename)
{
int status;
ini->readOnly = TRUE;
ini->filename = _strdup(filename);
status = IniFile_Load_File(ini, ini->filename);
if (status < 0)
return status;
status = IniFile_Load(ini);
return status;
}
wIniFileSection* IniFile_GetSection(wIniFile* ini, const char* name)
{
int index;
wIniFileSection* section = NULL;
for (index = 0; index < ini->nSections; index++)
{
if (_stricmp(name, ini->sections[index]->name) == 0)
{
section = ini->sections[index];
break;
}
}
return section;
}
wIniFileKey* IniFile_GetKey(wIniFile* ini, wIniFileSection* section, const char* name)
{
int index;
wIniFileKey* key = NULL;
for (index = 0; index < section->nKeys; index++)
{
if (_stricmp(name, section->keys[index]->name) == 0)
{
key = section->keys[index];
break;
}
}
return key;
}
char** IniFile_GetSectionNames(wIniFile* ini, int* count)
{
char* p;
int index;
int length;
int nameLength;
char** sectionNames;
wIniFileSection* section = NULL;
length = (sizeof(char*) * ini->nSections) + sizeof(char);
for (index = 0; index < ini->nSections; index++)
{
section = ini->sections[index];
nameLength = strlen(section->name);
length += (nameLength + 1);
}
sectionNames = (char**) malloc(length);
p = (char*) &((BYTE*) sectionNames)[sizeof(char*) * ini->nSections];
for (index = 0; index < ini->nSections; index++)
{
sectionNames[index] = p;
section = ini->sections[index];
nameLength = strlen(section->name);
CopyMemory(p, section->name, nameLength + 1);
p += (nameLength + 1);
}
*p = '\0';
*count = ini->nSections;
return sectionNames;
}
char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count)
{
char* p;
int index;
int length;
int nameLength;
char** keyNames;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return NULL;
length = (sizeof(char*) * pSection->nKeys) + sizeof(char);
for (index = 0; index < pSection->nKeys; index++)
{
pKey = pSection->keys[index];
nameLength = strlen(pKey->name);
length += (nameLength + 1);
}
keyNames = (char**) malloc(length);
p = (char*) &((BYTE*) keyNames)[sizeof(char*) * pSection->nKeys];
for (index = 0; index < pSection->nKeys; index++)
{
keyNames[index] = p;
pKey = pSection->keys[index];
nameLength = strlen(pKey->name);
CopyMemory(p, pKey->name, nameLength + 1);
p += (nameLength + 1);
}
*p = '\0';
*count = pSection->nKeys;
return keyNames;
}
char* IniFile_GetKeyValueString(wIniFile* ini, const char* section, const char* key)
{
char* value = NULL;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return NULL;
pKey = IniFile_GetKey(ini, pSection, key);
if (!pKey)
return NULL;
value = pKey->value;
return value;
}
UINT32 IniFile_GetKeyValueInt(wIniFile* ini, const char* section, const char* key)
{
UINT32 value = 0;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return 0;
pKey = IniFile_GetKey(ini, pSection, key);
if (!pKey)
return 0;
value = atoi(pKey->value);
return value;
}
wIniFile* IniFile_New()
{
wIniFile* ini = (wIniFile*) calloc(1, sizeof(wIniFile));
if (ini)
{
ini->nSections = 0;
ini->cSections = 64;
ini->sections = (wIniFileSection**) malloc(sizeof(wIniFileSection) * ini->cSections);
}
return ini;
}
void IniFile_Free(wIniFile* ini)
{
if (ini)
{
free(ini->filename);
free(ini);
}
}

View File

@ -5,6 +5,7 @@ set(MODULE_PREFIX "TEST_WINPR_UTILS")
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestIni.c
TestQueue.c
TestPrint.c
TestPubSub.c

View File

@ -0,0 +1,137 @@
#include <winpr/crt.h>
#include <winpr/ini.h>
const char TEST_INI_01[] =
"; This is a sample .ini config file\n"
"\n"
"[first_section]\n"
"one = 1\n"
"five = 5\n"
"animal = BIRD\n"
"\n"
"[second_section]\n"
"path = \"/usr/local/bin\"\n"
"URL = \"http://www.example.com/~username\"\n"
"\n";
const char TEST_INI_02[] =
"[FreeRDS]\n"
"prefix=\"/usr/local\"\n"
"bindir=\"bin\"\n"
"sbindir=\"sbin\"\n"
"libdir=\"lib\"\n"
"datarootdir=\"share\"\n"
"localstatedir=\"var\"\n"
"sysconfdir=\"etc\"\n"
"\n";
int TestIni(int argc, char* argv[])
{
int i, j;
int nKeys;
int nSections;
char* sValue;
UINT32 iValue;
wIniFile* ini;
char** keyNames;
char** sectionNames;
/* First Sample */
ini = IniFile_New();
IniFile_ParseString(ini, TEST_INI_01);
sectionNames = IniFile_GetSectionNames(ini, &nSections);
for (i = 0; i < nSections; i++)
{
keyNames = IniFile_GetSectionKeyNames(ini, sectionNames[i], &nKeys);
printf("[%s]\n", sectionNames[i]);
for (j = 0; j < nKeys; j++)
{
sValue = IniFile_GetKeyValueString(ini, sectionNames[i], keyNames[j]);
printf("%s = %s\n", keyNames[j], sValue);
}
free(keyNames);
}
free(sectionNames);
iValue = IniFile_GetKeyValueInt(ini, "first_section", "one");
if (iValue != 1)
{
printf("IniFile_GetKeyValueInt failure\n");
return -1;
}
iValue = IniFile_GetKeyValueInt(ini, "first_section", "five");
if (iValue != 5)
{
printf("IniFile_GetKeyValueInt failure\n");
return -1;
}
sValue = IniFile_GetKeyValueString(ini, "first_section", "animal");
if (strcmp(sValue, "BIRD") != 0)
{
printf("IniFile_GetKeyValueString failure\n");
return -1;
}
sValue = IniFile_GetKeyValueString(ini, "second_section", "path");
if (strcmp(sValue, "/usr/local/bin") != 0)
{
printf("IniFile_GetKeyValueString failure\n");
return -1;
}
sValue = IniFile_GetKeyValueString(ini, "second_section", "URL");
if (strcmp(sValue, "http://www.example.com/~username") != 0)
{
printf("IniFile_GetKeyValueString failure\n");
return -1;
}
IniFile_Free(ini);
/* Second Sample */
ini = IniFile_New();
IniFile_ParseString(ini, TEST_INI_02);
sectionNames = IniFile_GetSectionNames(ini, &nSections);
for (i = 0; i < nSections; i++)
{
keyNames = IniFile_GetSectionKeyNames(ini, sectionNames[i], &nKeys);
printf("[%s]\n", sectionNames[i]);
for (j = 0; j < nKeys; j++)
{
sValue = IniFile_GetKeyValueString(ini, sectionNames[i], keyNames[j]);
printf("%s = %s\n", keyNames[j], sValue);
}
free(keyNames);
}
free(sectionNames);
IniFile_Free(ini);
return 0;
}

View File

@ -0,0 +1,51 @@
# WinPR: Windows Portable Runtime
# libwinpr-wnd cmake build script
#
# Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(MODULE_NAME "winpr-wnd")
set(MODULE_PREFIX "WINPR_WND")
set(${MODULE_PREFIX}_SRCS
wnd.c
wnd.h)
if(MSVC AND (NOT MONOLITHIC_BUILD))
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)
endif()
add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT"
MONOLITHIC ${MONOLITHIC_BUILD}
SOURCES ${${MODULE_PREFIX}_SRCS})
set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION} PREFIX "lib")
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL
MODULE winpr
MODULES winpr-crt)
if(MONOLITHIC_BUILD)
else()
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT WinPRTargets)
endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR")
if(BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@ -0,0 +1,9 @@
set(MINWIN_LAYER "0")
set(MINWIN_GROUP "none")
set(MINWIN_MAJOR_VERSION "0")
set(MINWIN_MINOR_VERSION "0")
set(MINWIN_SHORT_NAME "wnd")
set(MINWIN_LONG_NAME "Window Notification")
set(MODULE_LIBRARY_NAME "${MINWIN_SHORT_NAME}")

View File

@ -0,0 +1,3 @@
LIBRARY "libwinpr-wnd"
EXPORTS

3
winpr/libwinpr/wnd/test/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
TestWnd
TestWnd.c

View File

@ -0,0 +1,32 @@
set(MODULE_NAME "TestWnd")
set(MODULE_PREFIX "TEST_WND")
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestWndCreateWindowEx.c
TestWndWmCopyData.c)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr
MODULES winpr-crt winpr-wnd winpr-library)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")

View File

@ -0,0 +1,97 @@
#include <winpr/crt.h>
#include <winpr/wnd.h>
#include <winpr/wtsapi.h>
#include <winpr/library.h>
const char* WM_WTS_STRINGS[] =
{
"",
"WTS_CONSOLE_CONNECT",
"WTS_CONSOLE_DISCONNECT",
"WTS_REMOTE_CONNECT",
"WTS_REMOTE_DISCONNECT",
"WTS_SESSION_LOGON",
"WTS_SESSION_LOGOFF",
"WTS_SESSION_LOCK",
"WTS_SESSION_UNLOCK",
"WTS_SESSION_REMOTE_CONTROL",
"WTS_SESSION_CREATE",
"WTS_SESSION_TERMINATE",
""
};
static LRESULT CALLBACK TestWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_WTSSESSION_CHANGE:
if (wParam && (wParam < 13))
{
PWTSSESSION_NOTIFICATION pNotification = (PWTSSESSION_NOTIFICATION) lParam;
printf("WM_WTSSESSION_CHANGE: %s SessionId: %d\n",
WM_WTS_STRINGS[wParam], (int) pNotification->dwSessionId);
}
break;
default:
printf("TestWndProc: uMsg: 0x%04X\n", uMsg);
return DefWindowProc(hwnd, uMsg, wParam, lParam);
break;
}
return 0;
}
int TestWndCreateWindowEx(int argc, char* argv[])
{
HWND hWnd;
HMODULE hModule;
HINSTANCE hInstance;
WNDCLASSEX wndClassEx;
WTSSESSION_NOTIFICATION wtsSessionNotification;
hModule = GetModuleHandle(NULL);
ZeroMemory(&wndClassEx, sizeof(WNDCLASSEX));
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.style = 0;
wndClassEx.lpfnWndProc = TestWndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hInstance = hModule;
wndClassEx.hIcon = NULL;
wndClassEx.hCursor = NULL;
wndClassEx.hbrBackground = NULL;
wndClassEx.lpszMenuName = _T("TestWndMenu");
wndClassEx.lpszClassName = _T("TestWndClass");
wndClassEx.hIconSm = NULL;
if (!RegisterClassEx(&wndClassEx))
{
printf("RegisterClassEx failure\n");
return -1;
}
hInstance = wndClassEx.hInstance;
hWnd = CreateWindowEx(0, wndClassEx.lpszClassName,
0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInstance, NULL);
if (!hWnd)
{
printf("CreateWindowEx failure\n");
return -1;
}
wtsSessionNotification.cbSize = sizeof(WTSSESSION_NOTIFICATION);
wtsSessionNotification.dwSessionId = 123;
SendMessage(hWnd, WM_WTSSESSION_CHANGE, WTS_SESSION_LOGON, (LPARAM) &wtsSessionNotification);
DestroyWindow(hWnd);
return 0;
}

View File

@ -0,0 +1,83 @@
#include <winpr/crt.h>
#include <winpr/wnd.h>
#include <winpr/library.h>
static LRESULT CALLBACK TestWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PCOPYDATASTRUCT pCopyData;
switch (uMsg)
{
case WM_COPYDATA:
{
pCopyData = (PCOPYDATASTRUCT) lParam;
if (!pCopyData)
break;
printf("WM_COPYDATA: cbData: %d dwData: %d\n",
(int) pCopyData->cbData, (int) pCopyData->dwData);
}
break;
case WM_CLOSE:
printf("WM_CLOSE\n");
break;
default:
printf("TestWndProc: uMsg: 0x%04X\n", uMsg);
return DefWindowProc(hwnd, uMsg, wParam, lParam);
break;
}
return 0;
}
int TestWndWmCopyData(int argc, char* argv[])
{
HWND hWnd;
HMODULE hModule;
HINSTANCE hInstance;
WNDCLASSEX wndClassEx;
hModule = GetModuleHandle(NULL);
ZeroMemory(&wndClassEx, sizeof(WNDCLASSEX));
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.style = 0;
wndClassEx.lpfnWndProc = TestWndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hInstance = hModule;
wndClassEx.hIcon = NULL;
wndClassEx.hCursor = NULL;
wndClassEx.hbrBackground = NULL;
wndClassEx.lpszMenuName = _T("TestWndMenu");
wndClassEx.lpszClassName = _T("TestWndClass");
wndClassEx.hIconSm = NULL;
if (!RegisterClassEx(&wndClassEx))
{
printf("RegisterClassEx failure\n");
return -1;
}
hInstance = wndClassEx.hInstance;
hWnd = CreateWindowEx(0, wndClassEx.lpszClassName,
0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInstance, NULL);
if (!hWnd)
{
printf("CreateWindowEx failure\n");
return -1;
}
SendMessage(hWnd, WM_CLOSE, 0, 0);
DestroyWindow(hWnd);
return 0;
}

427
winpr/libwinpr/wnd/wnd.c Normal file
View File

@ -0,0 +1,427 @@
/**
* WinPR: Windows Portable Runtime
* Window Notification System
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <winpr/collections.h>
#include <winpr/wnd.h>
#ifndef _WIN32
#include "wnd.h"
/**
* Custom Functions
*/
static wArrayList* g_WindowClasses = NULL;
void InitializeWindowClasses()
{
if (g_WindowClasses)
return;
g_WindowClasses = ArrayList_New(TRUE);
}
WNDCLASSEXA* CloneWindowClass(CONST WNDCLASSEXA* lpwcx)
{
WNDCLASSEXA* _lpwcx = NULL;
_lpwcx = malloc(sizeof(WNDCLASSEXA));
if (!_lpwcx)
return NULL;
CopyMemory(_lpwcx, lpwcx, sizeof(WNDCLASSEXA));
_lpwcx->lpszClassName = _strdup(lpwcx->lpszClassName);
_lpwcx->lpszMenuName = _strdup(lpwcx->lpszMenuName);
return _lpwcx;
}
WNDCLASSEXA* FindWindowClass(LPCSTR lpClassName)
{
int index;
int count;
BOOL found = FALSE;
WNDCLASSEXA* lpwcx = NULL;
ArrayList_Lock(g_WindowClasses);
count = ArrayList_Count(g_WindowClasses);
for (index = 0; index < count; index++)
{
lpwcx = (WNDCLASSEXA*) ArrayList_GetItem(g_WindowClasses, index);
if (strcmp(lpClassName, lpwcx->lpszClassName) == 0)
{
found = TRUE;
break;
}
}
ArrayList_Unlock(g_WindowClasses);
return (found) ? lpwcx : NULL;
}
/**
* Standard Functions
*/
WORD WINAPI GetWindowWord(HWND hWnd, int nIndex)
{
return 0;
}
WORD WINAPI SetWindowWord(HWND hWnd, int nIndex, WORD wNewWord)
{
return 0;
}
LONG WINAPI GetWindowLongA(HWND hWnd, int nIndex)
{
return 0;
}
LONG WINAPI GetWindowLongW(HWND hWnd, int nIndex)
{
return 0;
}
LONG WINAPI SetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong)
{
return 0;
}
LONG WINAPI SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong)
{
return 0;
}
LONG_PTR WINAPI GetWindowLongPtrA(HWND hWnd, int nIndex)
{
return 0;
}
LONG_PTR WINAPI GetWindowLongPtrW(HWND hWnd, int nIndex)
{
return 0;
}
LONG_PTR WINAPI SetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
return 0;
}
LONG_PTR WINAPI SetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
return 0;
}
BOOL WINAPI DestroyWindow(HWND hWnd)
{
WINPR_WND* pWnd;
pWnd = (WINPR_WND*) hWnd;
if (!pWnd)
return FALSE;
free(pWnd->lpClassName);
if (pWnd->lpWindowName)
free(pWnd->lpWindowName);
free(pWnd);
return TRUE;
}
VOID WINAPI PostQuitMessage(int nExitCode)
{
}
ATOM WINAPI RegisterClassA(CONST WNDCLASSA* lpWndClass)
{
return 1;
}
ATOM WINAPI RegisterClassW(CONST WNDCLASSW* lpWndClass)
{
return 1;
}
ATOM WINAPI RegisterClassExA(CONST WNDCLASSEXA* lpwcx)
{
WNDCLASSEXA* _lpwcx;
InitializeWindowClasses();
_lpwcx = CloneWindowClass(lpwcx);
ArrayList_Add(g_WindowClasses, (void*) _lpwcx);
return 1;
}
ATOM WINAPI RegisterClassExW(CONST WNDCLASSEXW* lpwcx)
{
return 1;
}
BOOL WINAPI UnregisterClassA(LPCSTR lpClassName, HINSTANCE hInstance)
{
return TRUE;
}
BOOL WINAPI UnregisterClassW(LPCWSTR lpClassName, HINSTANCE hInstance)
{
return TRUE;
}
HWND WINAPI CreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName,
LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
HWND hWnd;
WINPR_WND* pWnd;
WNDCLASSEXA* lpwcx;
InitializeWindowClasses();
if (!lpClassName)
return NULL;
lpwcx = FindWindowClass(lpClassName);
if (!lpwcx)
return NULL;
pWnd = (WINPR_WND*) calloc(1, sizeof(WINPR_WND));
if (!pWnd)
return NULL;
hWnd = (HWND) pWnd;
pWnd->X = X;
pWnd->Y = Y;
pWnd->nWidth = nWidth;
pWnd->nHeight = nHeight;
pWnd->lpClassName = _strdup(lpClassName);
if (lpWindowName)
pWnd->lpWindowName = _strdup(lpWindowName);
pWnd->hWndParent = hWndParent;
pWnd->hMenu = hMenu;
pWnd->hInstance = hInstance;
pWnd->lpParam = lpParam;
pWnd->lpwcx = lpwcx;
return hWnd;
}
HWND WINAPI CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
return NULL;
}
HWND WINAPI FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName)
{
return NULL;
}
HWND WINAPI FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName)
{
return NULL;
}
HWND WINAPI FindWindowExA(HWND hWndParent, HWND hWndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
{
return NULL;
}
HWND WINAPI FindWindowExW(HWND hWndParent, HWND hWndChildAfter, LPCWSTR lpszClass, LPCWSTR lpszWindow)
{
return NULL;
}
BOOL WINAPI GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax)
{
return TRUE;
}
BOOL WINAPI GetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax)
{
return TRUE;
}
DWORD WINAPI GetMessagePos(VOID)
{
return 0;
}
LONG WINAPI GetMessageTime(VOID)
{
return 0;
}
LPARAM WINAPI GetMessageExtraInfo(VOID)
{
return 0;
}
LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
{
return 0;
}
BOOL WINAPI SetMessageQueue(int cMessagesMax)
{
return TRUE;
}
LRESULT WINAPI SendMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
LRESULT status;
WINPR_WND* pWnd;
WNDPROC lpfnWndProc;
pWnd = (WINPR_WND*) hWnd;
if (!pWnd)
return 0;
lpfnWndProc = pWnd->lpwcx->lpfnWndProc;
if (!lpfnWndProc)
return 0;
status = lpfnWndProc(hWnd, Msg, wParam, lParam);
return status;
}
LRESULT WINAPI SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
LRESULT WINAPI SendMessageTimeoutA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult)
{
return 0;
}
LRESULT WINAPI SendMessageTimeoutW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
UINT fuFlags, UINT uTimeout, PDWORD_PTR lpdwResult)
{
return 0;
}
BOOL WINAPI SendNotifyMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return TRUE;
}
BOOL WINAPI SendNotifyMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return TRUE;
}
BOOL WINAPI SendMessageCallbackA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData)
{
return TRUE;
}
BOOL WINAPI SendMessageCallbackW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam,
SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData)
{
return TRUE;
}
BOOL WINAPI TranslateMessage(CONST MSG* lpMsg)
{
return TRUE;
}
LRESULT WINAPI DispatchMessageA(CONST MSG* lpMsg)
{
return 0;
}
LRESULT WINAPI DispatchMessageW(CONST MSG* lpMsg)
{
return 0;
}
BOOL WINAPI PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
{
return TRUE;
}
BOOL WINAPI PeekMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
{
return TRUE;
}
BOOL WINAPI ReplyMessage(LRESULT lResult)
{
return TRUE;
}
BOOL WINAPI WaitMessage(VOID)
{
return TRUE;
}
LRESULT WINAPI CallWindowProcA(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
LRESULT WINAPI CallWindowProcW(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
LRESULT WINAPI DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
LRESULT WINAPI DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}
#endif

41
winpr/libwinpr/wnd/wnd.h Normal file
View File

@ -0,0 +1,41 @@
/**
* WinPR: Windows Portable Runtime
* Window Notification System
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WINPR_WND_PRIVATE_H
#define WINPR_WND_PRIVATE_H
#include <winpr/wnd.h>
struct _WINPR_WND
{
int X;
int Y;
int nWidth;
int nHeight;
HMENU hMenu;
LPVOID lpParam;
HWND hWndParent;
LPSTR lpClassName;
LPSTR lpWindowName;
HINSTANCE hInstance;
WNDCLASSEXA* lpwcx;
};
typedef struct _WINPR_WND WINPR_WND;
#endif /* WINPR_WND_PRIVATE_H */

View File

@ -31,7 +31,7 @@ set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SO
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL
MODULE winpr
MODULES winpr-nt winpr-io winpr-synch winpr-file winpr-error winpr-library)
MODULES winpr-nt winpr-io winpr-synch winpr-file winpr-error winpr-library winpr-environment)
if(MONOLITHIC_BUILD)
set(WINPR_LIBS ${WINPR_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)

View File

@ -5,25 +5,186 @@
int TestWtsApiQuerySessionInformation(int argc, char* argv[])
{
DWORD index;
DWORD count;
BOOL bSuccess;
HANDLE hServer;
LPSTR pBuffer;
DWORD sessionId;
DWORD bytesReturned;
PWTS_SESSION_INFO pSessionInfo;
sessionId = 123;
hServer = WTS_CURRENT_SERVER_HANDLE;
pBuffer = NULL;
bytesReturned = 0;
count = 0;
pSessionInfo = NULL;
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSConnectState, &pBuffer, &bytesReturned);
bSuccess = WTSEnumerateSessions(hServer, 0, 1, &pSessionInfo, &count);
if (!bSuccess)
{
printf("WTSQuerySessionInformation failed: %d\n", (int) GetLastError());
//return -1;
printf("WTSEnumerateSessions failed: %d\n", (int) GetLastError());
return -1;
}
printf("WTSEnumerateSessions count: %d\n", (int) count);
for (index = 0; index < count; index++)
{
pBuffer = NULL;
bytesReturned = 0;
char* Username;
char* Domain;
char* ClientName;
ULONG ClientBuildNumber;
USHORT ClientProductId;
ULONG ClientHardwareId;
USHORT ClientProtocolType;
PWTS_CLIENT_DISPLAY ClientDisplay;
PWTS_CLIENT_ADDRESS ClientAddress;
WTS_CONNECTSTATE_CLASS ConnectState;
sessionId = pSessionInfo[index].SessionId;
printf("[%d] SessionId: %d State: %d\n", (int) index,
(int) pSessionInfo[index].SessionId,
(int) pSessionInfo[index].State);
/* WTSUserName */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSUserName, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSUserName failed: %d\n", (int) GetLastError());
return -1;
}
Username = (char*) pBuffer;
printf("\tWTSUserName: %s\n", Username);
/* WTSDomainName */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSDomainName, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSDomainName failed: %d\n", (int) GetLastError());
return -1;
}
Domain = (char*) pBuffer;
printf("\tWTSDomainName: %s\n", Domain);
/* WTSConnectState */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSConnectState, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSConnectState failed: %d\n", (int) GetLastError());
return -1;
}
ConnectState = *((WTS_CONNECTSTATE_CLASS*) pBuffer);
printf("\tWTSConnectState: %d\n", (int) ConnectState);
/* WTSClientBuildNumber */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientBuildNumber, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientBuildNumber failed: %d\n", (int) GetLastError());
return -1;
}
ClientBuildNumber = *((ULONG*) pBuffer);
printf("\tWTSClientBuildNumber: %d\n", (int) ClientBuildNumber);
/* WTSClientName */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientName, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientName failed: %d\n", (int) GetLastError());
return -1;
}
ClientName = (char*) pBuffer;
printf("\tWTSClientName: %s\n", ClientName);
/* WTSClientProductId */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientProductId, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientProductId failed: %d\n", (int) GetLastError());
return -1;
}
ClientProductId = *((USHORT*) pBuffer);
printf("\tWTSClientProductId: %d\n", (int) ClientProductId);
/* WTSClientHardwareId */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientHardwareId, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientHardwareId failed: %d\n", (int) GetLastError());
return -1;
}
ClientHardwareId = *((ULONG*) pBuffer);
printf("\tWTSClientHardwareId: %d\n", (int) ClientHardwareId);
/* WTSClientAddress */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientAddress, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientAddress failed: %d\n", (int) GetLastError());
return -1;
}
ClientAddress = (PWTS_CLIENT_ADDRESS) pBuffer;
printf("\tWTSClientAddress: AddressFamily: %d\n",
(int) ClientAddress->AddressFamily);
/* WTSClientDisplay */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientDisplay, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientDisplay failed: %d\n", (int) GetLastError());
return -1;
}
ClientDisplay = (PWTS_CLIENT_DISPLAY) pBuffer;
printf("\tWTSClientDisplay: HorizontalResolution: %d VerticalResolution: %d ColorDepth: %d\n",
(int) ClientDisplay->HorizontalResolution, (int) ClientDisplay->VerticalResolution,
(int) ClientDisplay->ColorDepth);
/* WTSClientProtocolType */
bSuccess = WTSQuerySessionInformation(hServer, sessionId, WTSClientProtocolType, &pBuffer, &bytesReturned);
if (!bSuccess)
{
printf("WTSQuerySessionInformation WTSClientProtocolType failed: %d\n", (int) GetLastError());
return -1;
}
ClientProtocolType = *((USHORT*) pBuffer);
printf("\tWTSClientProtocolType: %d\n", (int) ClientProtocolType);
}
WTSFreeMemory(pSessionInfo);
return 0;
}

View File

@ -22,8 +22,11 @@
#endif
#include <winpr/crt.h>
#include <winpr/ini.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/library.h>
#include <winpr/environment.h>
#include <winpr/wtsapi.h>
@ -394,16 +397,25 @@ BOOL WTSRegisterWtsApiFunctionTable(PWtsApiFunctionTable table)
return TRUE;
}
void InitializeWtsApiStubs(void)
void InitializeWtsApiStubs_Env()
{
DWORD nSize;
char* env = NULL;
INIT_WTSAPI_FN pInitWtsApi;
g_Initialized = TRUE;
if (g_WtsApi)
return;
g_WtsApiModule = LoadLibraryA("/opt/freerds/lib64/libfreerds-fdsapi.so");
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0);
if (nSize)
{
env = (LPSTR) malloc(nSize);
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize);
}
if (env)
g_WtsApiModule = LoadLibraryA(env);
if (!g_WtsApiModule)
return;
@ -415,3 +427,69 @@ void InitializeWtsApiStubs(void)
g_WtsApi = pInitWtsApi();
}
}
void InitializeWtsApiStubs_FreeRDS()
{
char* prefix;
char* libdir;
wIniFile* ini;
if (g_WtsApi)
return;
ini = IniFile_New();
if (IniFile_Parse(ini, "/var/run/freerds.instance") < 0)
{
printf("failed to parse freerds.instance\n");
}
prefix = IniFile_GetKeyValueString(ini, "FreeRDS", "prefix");
libdir = IniFile_GetKeyValueString(ini, "FreeRDS", "libdir");
printf("FreeRDS: %s / %s\n", prefix, libdir);
if (prefix && libdir)
{
char* prefix_libdir;
char* wtsapi_library;
prefix_libdir = GetCombinedPath(prefix, libdir);
wtsapi_library = GetCombinedPath(prefix_libdir, "libfreerds-fdsapi.so");
if (wtsapi_library)
{
INIT_WTSAPI_FN pInitWtsApi;
g_WtsApiModule = LoadLibraryA(wtsapi_library);
if (g_WtsApiModule)
{
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
if (pInitWtsApi)
{
g_WtsApi = pInitWtsApi();
}
}
}
free(prefix_libdir);
free(wtsapi_library);
}
IniFile_Free(ini);
}
void InitializeWtsApiStubs(void)
{
if (g_Initialized)
return;
g_Initialized = TRUE;
InitializeWtsApiStubs_Env();
if (!g_WtsApi)
InitializeWtsApiStubs_FreeRDS();
}