Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified iishwc/iishwcx64.exe
Binary file not shown.
Binary file modified iishwc/iishwcx86.exe
Binary file not shown.
70 changes: 49 additions & 21 deletions iishwc/src/iishwc/iishwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,31 @@
// Set the project's calling convention to "__stdcall (/Gz)".
// Use Windows Events or IPC communication with the DEA http://msdn.microsoft.com/en-us/library/System.Threading.EventWaitHandle.aspx


HANDLE hStopEvent;

BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
SetEvent(hStopEvent);
return(TRUE);

default:
return FALSE;
}
}



// First argument is the path to the application host config.
HRESULT _cdecl wmain(int argc, wchar_t * argv[])
{
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);

// Create a handle for the Web core DLL.
HINSTANCE hDLL;

Expand All @@ -24,7 +46,7 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
WCHAR wszInstanceName[30];

// Retrieve the path of the Inetsrv folder.
DWORD nSize = ::ExpandEnvironmentStringsW(L"%windir%\\system32\\inetsrv",wszInetPath,MAX_PATH);
DWORD nSize = ::ExpandEnvironmentStringsW(L"%windir%\\system32\\inetsrv", wszInetPath, MAX_PATH);

// Exit if the path of the Inetsrv folder cannot be determined.
if (nSize == 0)
Expand All @@ -33,33 +55,36 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
hr = HRESULT_FROM_WIN32(GetLastError());
// Return an error status to the console.
printf("Could not determine the path to the Inetsrv folder.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
// Return an error from the application and exit.
return hr;
}

// Append the Web core DLL name to the Inetsrv path.
wcscpy_s(wszDllPath,MAX_PATH-1,wszInetPath);
wcscat_s(wszDllPath,MAX_PATH-1,L"\\");
wcscat_s(wszDllPath,MAX_PATH-1,WEB_CORE_DLL_NAME);
wcscpy_s(wszDllPath, MAX_PATH - 1, wszInetPath);
wcscat_s(wszDllPath, MAX_PATH - 1, L"\\");
wcscat_s(wszDllPath, MAX_PATH - 1, WEB_CORE_DLL_NAME);

if (argc == 4)
{
// Use the first argument from the run command as the config file path
wcscpy_s(wszCfgPath,MAX_PATH-1,argv[1]);
wcscpy_s(wszCfgPath, MAX_PATH - 1, argv[1]);

// Use the second argument from the run command as the root web config file path
wcscpy_s(wszRootWebCfgPath,MAX_PATH-1,argv[2]);
wcscpy_s(wszRootWebCfgPath, MAX_PATH - 1, argv[2]);

// Use the third argument as the name of the web core instance
wcscpy_s(wszInstanceName,29,argv[3]);
wcscpy_s(wszInstanceName, 29, argv[3]);
}
else
{
printf("Invalid parameters, use the following: iishwc [applicationHost.config] [rootweb.config] [instance-id]");
return 1;
}

hStopEvent = CreateEvent(NULL, true, false, NULL);
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);

// Create a pointer to WebCoreActivate.
PFN_WEB_CORE_ACTIVATE pfnWebCoreActivate = NULL;

Expand All @@ -76,39 +101,39 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
hr = HRESULT_FROM_WIN32(GetLastError());
// Return an error status to the console.
printf("Could not load DLL.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
}
else
{
// Return a success status to the console.
printf("DLL loaded successfully.\n");
// Retrieve the address for "WebCoreActivate".
pfnWebCoreActivate = (PFN_WEB_CORE_ACTIVATE)GetProcAddress(
hDLL,"WebCoreActivate");
hDLL, "WebCoreActivate");
// Test for an error.
if (pfnWebCoreActivate==NULL)
if (pfnWebCoreActivate == NULL)
{
// Retrieve the last error.
hr = HRESULT_FROM_WIN32(GetLastError());
// Return an error status to the console.
printf("Could not resolve WebCoreActivate.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
}
else
{
// Return a success status to the console.
printf("WebCoreActivate successfully resolved.\n");
// Retrieve the address for "WebCoreShutdown".
pfnWebCoreShutdown = (PFN_WEB_CORE_SHUTDOWN)GetProcAddress(
hDLL,"WebCoreShutdown");
hDLL, "WebCoreShutdown");
// Test for an error.
if (pfnWebCoreShutdown==NULL)
if (pfnWebCoreShutdown == NULL)
{
// Retrieve the last error.
hr = HRESULT_FROM_WIN32(GetLastError());
// Return an error status to the console.
printf("Could not resolve WebCoreShutdown.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
}
else
{
Expand All @@ -123,16 +148,19 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
{
// Return an error status to the console.
printf("WebCoreActivate failed.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
}
else
{
// Return a success status to the console.
printf("WebCoreActivate was successful.\n");

// Prompt the user to continue.
printf("Press any key to continue...\n");
// Wait for a key press.
int iKeyPress = _getch();
printf("Press Ctrl-C to stop.\n");

// Wait for stop event.
WaitForSingleObject(hStopEvent, INFINITE);

// Return a shutdown status to the console.
printf("Shutting down the Web core...\n");
// Shut down the Web core.
Expand All @@ -142,7 +170,7 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
{
// Return an error status to the console.
printf("WebCoreShutdown failed.\n");
printf("Error: 0x%x\n",hr);
printf("Error: 0x%x\n", hr);
}
else
{
Expand All @@ -154,7 +182,7 @@ HRESULT _cdecl wmain(int argc, wchar_t * argv[])
}
// Release the DLL.
FreeLibrary(hDLL);
}
}
// Return the application status.
return hr;
}