终于解决了,ISAPI在返回时是一个图片而不是一个网页的问题了,为了这个东西我试验了ATL SERVER也不好用,挺郁闷的。但是还好,最后 在CSDN 上若要以除 HTML 之外的其他格式发送回来自 ISAPI 服务器的数据
GIF 格式,该格式是二进制格式。若要发送回二进制数据,例如将 GIF 格式图像作为输出,将需要完成某些替换步骤。因为 CHtmlStream 类不允许单独的字节流,所以需要创建从 CHtmlStream 派生的类,然后使用该类将输出发送到客户端。下面是示例类:
class CBinaryHtmlStream : public CHtmlStream { public: // we have a special overload of << to allow for a single byte CBinaryHtmlStream& operator<<(BYTE b) { Write(&b, 1); return *this; } }
若要使用此流发送数据,请用以下主干代码代替 OutputXBM
函数:
static const TCHAR szContentType[] = _T("Content-Type: image/gif/r/n"); void CCounterExtension::OutputXBM(CHttpServerContext* pCtxt, CString& szDigits) { // some code here which takes szDigits and creates a new image // which has the GIF representation of those digits. This // image will be stored in memory at m_ImageByteArray[]. // The number of bytes in the image is stored in m_nNumberBytes. // Start by writing the proper content type to the client AddHeader(pCtxt, szContentType); CString strLength; strLength.Format("Content-Length: %d/r/n", m_nNumberBytes); AddHeader(pCtxt, (LPCTSTR)strLength); CBinaryHtmlStream* pStream = new CBinaryHtmlStream; ISAPIVERIFY(pStream != NULL); int nCount; for (nCount = 0; nCount<m_nNumberBytes; nCount++) *pStream << m_ImageByteArray[nCount]; *pCtxt << *pStream; delete pStream; // ... more code here ... }
最终我对程序加以改造实现了,希望以后和大家多多交流,CSDN上说的没有错,但是还是需要在改进一下 m_ImageByteArray[nCount]
目前我是把图片从本地磁盘上读出来,然后
用一个BYTE *pa= new BYTE[NN]存储;然后代替才达到输出成功的效果,多多指教!