locked
ISAPI filter not working RRS feed

  • Question

  • Hello again community:

    Please forgive me if this is a really dumb mistake (which I suspect it is). I have followed all the online recommendations I found about this. I compilled with no errors my ISAPI filter in Visual C++ Express Edition 2010 under Windows 7,Then I installed the ISAPI filter in the IIS and restarted the IIS. And it keeps showing this error:

    HTTP Error 500.0 - Internal Server Error

    Calling GetProcAddress on ISAPI filter "D:\isapiproject\Release\0719_isapi.dll" failed

    Entering the Event Viewer it shows this:

    Could not load all ISAPI filters for site 'DEFAULT WEB SITE'.  Therefore site startup aborted.

    EventData
    SiteName DEFAULT WEB SITE
    7F000000

    Searching the web for clues about this, it seems I am not exporting correctly the two main procedures:

    GetFilterVersion and HttpFilterProc

    However, I am (supposedly) doing it right.

    This is the main CPP code.

    // 0719_isapi.cpp : Defines the exported functions for the DLL application.
    //
    
    #include "stdafx.h"
    #include "0719_isapi.h"
    #include <windows.h>
    #include <httpfilt.h>
    #include <stdio.h>
    #include <sql.h>
    #include <sqltypes.h>
    #include <sqlext.h>  
    
    #define BUFFER_SIZE 2048
    
    
    // This is an example of an exported variable
    MY0719_ISAPI_API int nMy0719_isapi=0;
    
    // This is an example of an exported function.
    MY0719_ISAPI_API int fnMy0719_isapi(void)
    {
    	return 42;
    }
    
    BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer)
    {
    	// Specify the filter version and description.
    	pVer->dwFilterVersion = HTTP_FILTER_REVISION;
    	lstrcpy(pVer->lpszFilterDesc, "WebTrace");
    	// Specify the filter notifications.
    	pVer->dwFlags = SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_PREPROC_HEADERS;
    
    	return TRUE;
    }
    
    DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD NotificationType, LPVOID pvNotification )
    {
        if (NotificationType == SF_NOTIFY_PREPROC_HEADERS)
        {
    		char szServerName[BUFFER_SIZE] = "";
    		char szSecure[2] = "";
    		char szLocationHeader[BUFFER_SIZE + 32] = "";
    		char szRequest[BUFFER_SIZE] = "";
    		char szHost[BUFFER_SIZE] = "";
    		char szServerSoftware[BUFFER_SIZE] = "";
    		DWORD dwBuffSize = 0;
    
    		SQLHANDLE hdlEnv, hdlConn, hdlStmt, hdlDbc = NULL;
    
    		SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
    		char* dsnName = "DB0045";
            char* userID = "id_894784";
            char* passwd = "k39d4fk9k37hg6v4s6";
    		
    		// Retrieve the URL for the request.
    		dwBuffSize = BUFFER_SIZE;
    		pfc->GetServerVariable(pfc, "URL",szRequest, &dwBuffSize);
    
    		// Retrieve the host name (name of the computer who is calling)
    		dwBuffSize = BUFFER_SIZE;
    		pfc->GetServerVariable(pfc, "HTTP_HOST",szHost, &dwBuffSize);
    
    		// Retrieve the version of the IIS.
    		dwBuffSize = BUFFER_SIZE;
    		pfc->GetServerVariable(pfc, "SERVER_SOFTWARE",szServerSoftware, &dwBuffSize);
    
    		// Retrieve the server name.
    		dwBuffSize = BUFFER_SIZE;
    		pfc->GetServerVariable(pfc, "SERVER_NAME",szServerName, &dwBuffSize);
    		
    		// Specify the redirection header.
    		// wsprintf ( szLocationHeader, "Location: https://%s/%s\r\n\r\n",szServerName, &szRequest[1] );
    		// pfc->AddResponseHeaders ( pfc, szLocationHeader, 0);
    		// pfc->ServerSupportFunction ( pfc, SF_REQ_SEND_RESPONSE_HEADER, "302 Object Moved",(DWORD)"Please resubmit the request using a secure port.", 0 );
    
    		char MyQuery [1000];
    		sprintf_s(MyQuery,"update _LOG_ACTIVITY set LA_DATE = SYSDATETIME(), LA_URL='%s',LA_HOST='%s',LA_SERVER='%s',LA_SOFTWARE='%s'  where LA_ID in (select top 1 LA_ID from _LOG_ACTIVITY where LA_DATE in (select MIN(LA_DATE) from _LOG_ACTIVITY))",szRequest,szHost,szServerName,szServerSoftware);
    
        SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
        SQLAllocHandle (SQL_HANDLE_DBC, hdlEnv, &hdlConn);
        SQLConnect     (hdlConn, (SQLCHAR*)dsnName,SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS);
        SQLAllocHandle (SQL_HANDLE_STMT, hdlDbc, &hdlStmt);
        SQLExecDirect  (hdlStmt, (SQLCHAR*)MyQuery, SQL_NTS); 
    
        SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
        SQLFreeHandle(SQL_HANDLE_DBC, hdlConn);
        SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
    
    	return SF_STATUS_REQ_FINISHED;
    	}
    
    	return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }
    
    
    // This is the constructor of a class that has been exported.
    // see 0719_isapi.h for the class definition
    CMy0719_isapi::CMy0719_isapi()
    {
    	return;
    }
    

    And this is the H code: As you can see, the two procedures for exporting are inside the list at the bottom.

    Any suggestion or clue about this will be greatly appreciated.

    Thanks for your time!

    #ifdef MY0719_ISAPI_EXPORTS
    #define MY0719_ISAPI_API __declspec(dllexport)
    #else
    #define MY0719_ISAPI_API __declspec(dllimport)
    #endif
    
    #include <httpfilt.h>
    
    // This class is exported from the 0719_isapi.dll
    class MY0719_ISAPI_API CMy0719_isapi {
    public:
    	CMy0719_isapi(void);
    	// TODO: add your methods here.
    	BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer);
    	DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD NotificationType, LPVOID pvNotification );
    };
    
    extern MY0719_ISAPI_API int nMy0719_isapi;
    
    MY0719_ISAPI_API int fnMy0719_isapi(void);
    BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer);
    DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD NotificationType, LPVOID pvNotification );

    Thursday, July 19, 2012 5:22 PM

Answers

  • On 7/19/2012 1:22 PM, Grildrig wrote:

    Please forgive me if this is a really dumb mistake (which I suspect it is). I have followed all the online recommendations I found about this. I compilled with no errors my ISAPI filter in Visual C++ Express Edition 2010 under Windows 7,Then I installed the ISAPI filter in the IIS and restarted the IIS. And it keeps showing this error:HTTP Error 500.0 - Internal Server ErrorCalling GetProcAddress on ISAPI filter "D:\isapiproject\Release\0719_isapi.dll" failed

    Most likely, your functions are exported under decorated names. Inspect your DLL in Dependency Walker (http://www.dependencywalker.com) to see what it actually exports.

    In order to export your functions without any decorations, you need to use a DEF file:

    http://msdn.microsoft.com/en-us/library/d91k01sh.aspx


    Igor Tandetnik

    • Proposed as answer by i1friend Monday, July 23, 2012 9:12 AM
    • Marked as answer by Elegentin Xie Wednesday, July 25, 2012 9:13 AM
    Thursday, July 19, 2012 5:30 PM