我發現了下面的代碼片段,並試圖使用它創建一個ISAPI .DLL。類型/轉換錯誤試圖構建C++ .DLL
#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;
}
我使用VS 2010 Express創建了一個新的C++項目。我在構建項目時出現以下錯誤:
------ Build started: Project: ISAPIHttpOnly, Configuration: Debug Win32 ------
HttpOnly.cpp
c:\documents and settings\bob\my documents\visual studio 2010\projects\isapihttponly\isapihttponly\httponly.cpp(25): error C2664: 'StringCchCatW' : cannot convert parameter 1 from 'CHAR [2048]' to 'STRSAFE_LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我不知道如何解決此問題。 :S
您的程序正在編譯爲Unicode,請嘗試將'CHAR'更改爲'TCHAR'。 –
我不確定是否要將所有CHAR改爲TCHAR。我試過了,它產生了大約10個錯誤。 – rwkiii