我正在执行一些与Cookie相关的任务,为此,我使用了以下文章http://msdn.microsoft.com/en-us/library/ms972826

在编译以下代码时,

#include <windows.h>
#include <httpfilt.h>
#include "tchar.h"
#include "strsafe.h"

// Portion of HttpOnly
DWORD WINAPI HttpFilterProc(
   PHTTP_FILTER_CONTEXT pfc,
   DWORD dwNotificationType,
   LPVOID pvNotification) {

   // Hard coded cookie length (2k bytes)
   CHAR szCookie[2048];
   DWORD cbCookieOriginal = sizeof(szCookie) / sizeof(szCookie[0]);
   DWORD cbCookie = cbCookieOriginal;

      HTTP_FILTER_SEND_RESPONSE *pResponse =
         (HTTP_FILTER_SEND_RESPONSE*)pvNotification;

      CHAR *szHeader = "Set-Cookie:";
      CHAR *szHttpOnly = "; HttpOnly";
      if (pResponse->GetHeader(pfc,szHeader,szCookie,&cbCookie)) {
         if (SUCCEEDED(StringCchCat(szCookie,
                                    cbCookieOriginal,
                                    szHttpOnly))) {
            if (!pResponse->SetHeader(pfc,
                                      szHeader,
                                      szCookie)) {
                        // Fail securely - send no cookie!
                        pResponse->SetHeader(pfc,szHeader,"");
               }
            } else {
               pResponse->SetHeader(pfc,szHeader,"");
          }
   }

   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

我收到以下错误:错误C2375:'HttpFilterProc':重新定义;不同的链接

如何解决这个错误?

最佳答案

添加一个extern "C":

extern "C" DWORD WINAPI HttpFilterProc(
    PHTTP_FILTER_CONTEXT pfc,
    DWORD dwNotificationType,
    LPVOID pvNotification)
{
//...
}

我怀疑HttpFilterProc在 header httpfilt.h中声明为extern“C”。

09-07 09:41