1 #if defined(_WIN64) && !defined(UNICODE)
4 #if defined(UNICODE) && !defined(_UNICODE)
7 #if defined(_UNICODE) && !defined(UNICODE)
10 #if defined(_MSC_VER) && !defined(_WIN32_WINNT)
11 #define _WIN32_WINNT 0x0333 /* 3.51 */
21 #pragma comment(lib,"delayimp")
23 * CL command line should also be complemented with following:
25 * /link /delayload:advapi32.dll /delayload:user32.dll
27 * This is required if/as we want to support Win9x. With delayloaded
28 * DLLs in question all we have to do is to make sure NT-specific
29 * functions are not actually called under Win9x.
33 #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
39 GetDesktopWindow(); /* return value is ignored */
41 h
= GetProcessWindowStation();
42 if (h
==NULL
) return -1;
44 if (GetUserObjectInformationW (h
,UOI_NAME
,NULL
,0,&len
) ||
45 GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
48 if (len
>512) return -1; /* paranoia */
49 len
++,len
&=~1; /* paranoia */
51 name
=(WCHAR
*)_alloca(len
+sizeof(WCHAR
));
53 name
=(WCHAR
*)alloca(len
+sizeof(WCHAR
));
55 if (!GetUserObjectInformationW (h
,UOI_NAME
,name
,len
,&len
))
58 len
++,len
&=~1; /* paranoia */
59 name
[len
/sizeof(WCHAR
)]=L
'\0'; /* paranoia */
61 /* This doesn't cover "interactive" services [working with real
62 * WinSta0's] nor programs started non-interactively by Task
63 * Scheduler [those are working with SAWinSta]. */
64 if (wcsstr(name
,L
"Service-0x")) return 1;
66 /* This covers all non-interactive programs such as services. */
67 if (!wcsstr(name
,L
"WinSta0")) return 1;
73 static TCHAR msg
[128];
75 static void unimplemented ()
77 #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
78 /* this -------------v--- guards NT-specific calls */
79 if (GetVersion() < 0x80000000 && IsService())
80 { HANDLE h
= RegisterEventSource(0,_T("OPENSSL"));
82 ReportEvent(h
,EVENTLOG_ERROR_TYPE
,0,0,0,1,0,&pmsg
,0);
83 DeregisterEventSource(h
);
91 m
.lpszCaption
= _T("OpenSSL: FATAL");
94 m
.lpszIcon
= IDI_ERROR
;
95 m
.dwContextHelpId
= 0;
96 m
.lpfnMsgBoxCallback
= NULL
;
97 m
.dwLanguageId
= MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
);
100 MessageBoxIndirect (&m
);
105 void OPENSSL_Uplink (void **table
, int index
)
106 { static HMODULE app
=NULL
;
107 static void **applinktable
=NULL
;
110 len
= _stprintf (msg
,_T("OPENSSL_Uplink(%p,%02X): "),table
,index
);
111 _tcscpy (msg
+len
,_T("unimplemented function"));
112 table
[index
] = unimplemented
;
114 if (app
==NULL
&& (app
=GetModuleHandle(NULL
))==NULL
)
115 { app
=(HMODULE
)-1; _tcscpy (msg
+len
,_T("no host application"));
118 else if (app
==(HMODULE
)-1) { return; }
120 if (applinktable
==NULL
)
121 { void**(*applink
)();
123 applink
=(void**(*)())GetProcAddress(app
,"OPENSSL_Applink");
125 { app
=(HMODULE
)-1; _tcscpy (msg
+len
,_T("no OPENSSL_Applink"));
128 applinktable
= (*applink
)();
129 if (applinktable
==NULL
)
130 { app
=(HMODULE
)-1; _tcscpy (msg
+len
,_T("no ApplinkTable"));
135 if (index
> (int)applinktable
[0]) { return; }
137 if (applinktable
[index
]) table
[index
] = applinktable
[index
];
140 #if defined(_MSC_VER) && defined(_M_IX86)
142 __declspec(naked) static void lazy##i () { \
144 _asm push OFFSET OPENSSL_UplinkTable \
145 _asm call OPENSSL_Uplink \
147 _asm jmp OPENSSL_UplinkTable+4*i }
150 #error "Add more stubs..."
152 /* make some in advance... */
153 LAZY(1) LAZY(2) LAZY(3) LAZY(4) LAZY(5)
154 LAZY(6) LAZY(7) LAZY(8) LAZY(9) LAZY(10)
155 LAZY(11) LAZY(12) LAZY(13) LAZY(14) LAZY(15)
156 LAZY(16) LAZY(17) LAZY(18) LAZY(19) LAZY(20)
157 void *OPENSSL_UplinkTable
[] = {
159 lazy1
, lazy2
, lazy3
, lazy4
, lazy5
,
160 lazy6
, lazy7
, lazy8
, lazy9
, lazy10
,
161 lazy11
,lazy12
,lazy13
,lazy14
,lazy15
,
162 lazy16
,lazy17
,lazy18
,lazy19
,lazy20
,
167 main() { UP_fprintf(UP_stdout
,"hello, world!\n"); }