Reputation: 5846
I found the following snippet of code and am trying to create an ISAPI .DLL using it.
#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;
}
I created a new C++ project using VS 2010 Express. I get the following error when I build the project:
------ 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 ==========
I'm not sure how to resolve this. :S
Upvotes: 2
Views: 973
Reputation: 4078
Your program is being compiled as Unicode, then STRSAFE_LPWSTR
, which is the type from the first parameter in StringCchCat
, is failing against an char
array type, which is not Unicode.
To solve this, you have two choices, one is to declare the erroneous string as an TCHAR
array, so it can be preprocessed to an wchar_t
array. But then you'd have to change a lot of things in your code, like literal trings would need the TEXT("")
macro, etc.
But as it seems, your program was not done to use Unicode strings, so the other choice is to compile your program as Multi-Byte, then you don't need to change anything in your code because StringCchCat
will have a STRSAFE_LPSTR
parameter, which will be preprocessed to char *
.
To compile as Multi-Byte, just go to Project Settings->General->Character Set.
Upvotes: 4