Esempio n. 1
0
	//这个函数的特点是可以指定输入数据的长度,注意,input的有效数据长度必须是16的整数倍,input的大小必须大于等于len。
	//但是outbuf仅仅存储,有效的输出长度。
	int Aes::DecryptEcb(Memory<char>& outbuf,const void* input,int len){
		if(len<=0) return 0;
		if(outbuf.Length()<(uint)len){
			if(!outbuf.SetLength(len)) return 0;
		}
		return DecryptEcb(outbuf.Handle(),len,input,len);
	}
Esempio n. 2
0
	uint Image::GetPropertyItem(Memory<ImageItem>& tms){
		if(!_image) return 0;
		int nSize = ((_Image*)_image)->GetPropertyItemSize(PropertyTagFrameDelay);   
		tms.SetLength(nSize);
		((_Image*)_image)->GetPropertyItem(PropertyTagFrameDelay, nSize, (Gdiplus::PropertyItem*)tms.Handle());   
		return nSize;
	}
Esempio n. 3
0
	uint Image::FrameCount(){
		if(!_image) return 0;
		UINT count = ((_Image*)_image)->GetFrameDimensionsCount();   
		Memory<GUID> ids;
		ids.SetLength(count);
		((_Image*)_image)->GetFrameDimensionsList(ids, count);   
		return ((_Image*)_image)->GetFrameCount(ids);   
	}
Esempio n. 4
0
	int Base64::Encode(Memory<char>& output,const void* data,int len){
		int dlen = 0;
		base64_encode(0,&dlen,(uchar*)data,len);
		if(dlen==0) return 0;
		if(!output.SetLength(dlen)) return 0;
		base64_encode((byte*)output.Handle(),&dlen,(uchar*)data,len);
		return dlen;
	}
Esempio n. 5
0
	int Base64::Decode(Memory<char>& output,const char* data,int len){
		if(len==-1) len = strlen(data);
		int dlen = 0;
		base64_decode(0,&dlen,(uchar*)data,len);
		if(dlen==0) return 0;
		if(!output.SetLength(dlen)) return 0;
		base64_decode((byte*)output.Handle(),&dlen,(uchar*)data,len);
		return dlen;
	}
Esempio n. 6
0
	//返回值是加密数据的长度,outbuf会自动设置大小,但是不一定是数据长度,可能大于它。
	int Aes::EncryptEcb(Memory<char>& outbuf,const void* input,int len){
		if(len<=0) return 0;
		int lastn = len&0xF;
		int outLen;
		if(lastn) outLen = len - lastn + 16;
		else outLen = len;
		if(outbuf.Length()<(uint)outLen){
			if(!outbuf.SetLength(outLen)) return 0;
		}
		return EncryptEcb(outbuf.Handle(),outLen,input,len);
	}
Esempio n. 7
0
	UINT_PTR FileDialog::OFNHookProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{
		if(_Handle==0) _Handle = ::GetParent(hDlg);
		if(uMsg==WM_NOTIFY)
		{
			LPOFNOTIFY pon = (LPOFNOTIFY)lParam;
			switch(pon->hdr.code)
			{
			case CDN_SELCHANGE:
				{
					/*if(OnSelChange.IsNull()) break;
					Memory<wchar_t> path(MAX_PATH),file(MAX_PATH);
					int n = (int)::SendMessage(_Handle,CDM_GETFILEPATH,(WPARAM)MAX_PATH,(LPARAM)path.Handle());
					这个消息返回的值包括目录和文件名,目录们没有引号,文件名用空格分隔并且用引号包围,目录和文件名之间没有空格,目录末尾包含反斜杠。
					但是引号有时没有,有时有,如果文件名包含空格,实际上无法正确获取文件名,所以此方法实际上不可用。
					if(n<0) path[0] = 0;
					n = (int)::SendMessage(_Handle,CDM_GETSPEC,(WPARAM)MAX_PATH,(LPARAM)file.Handle());
					这个消息返回文件名,规则同上。
					if(n<0) path[0] = 0;
					OnSelChange(path,file);*/
					break;
				}
			case CDN_FOLDERCHANGE:
				{
					if(!OnFolderChange.IsNull()){
						Memory<wchar_t> path;
						path.SetLength(MAX_PATH);
						int n = (int)::SendMessage(_Handle,CDM_GETFOLDERPATH,(WPARAM)MAX_PATH,(LPARAM)path.Handle());
						if(n<0){
							path[0] = 0;
						}
						OnFolderChange(path,this);
					}
					break;
				}
			case CDN_FILEOK://this message is ago okid message,if return TRUE then no okid message;
				if((!OnFileOk.IsNull())&&(OnFileOk(pon->lpOFN,this)))
				{
					SetWindowLong(_Handle,DWL_MSGRESULT,1L);
					return 1;
				}
				break;
			case CDN_TYPECHANGE:
				if(!OnTypeChange.IsNull()) OnTypeChange(pon->lpOFN->nFilterIndex,this);
				break;
			}
		}
		return 0;
	};
Esempio n. 8
0
	int Image::Save(Memory<char>& mem,LPCWSTR type,long quality){
		if(_image==0) return 0;

		CLSID clsid;
		//未知原因,如果不用一个变量转换一下,type是一个常量字串的话,如果把 type 直接传给 GetImageEncoderClsid 会引起程序崩溃。
		//wchar_t tp[256];
		//这样也不行。
		//cs::WcsCopy(tp,type);
		cs::String tp = type;
		if(!GetImageEncoderClsid(tp,&clsid)) return 0;

		if(quality>100) quality = 100;
		if(quality<0) quality = 0;
		Gdiplus::EncoderParameters eps;
		eps.Count = 1;
		eps.Parameter[0].Guid = Gdiplus::EncoderQuality;
		eps.Parameter[0].NumberOfValues = 1;
		eps.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
		eps.Parameter[0].Value = &quality;

		IStream* stream;
		if(FAILED(CreateStreamOnHGlobal(0,1,&stream))) return 0;
		if(((_Image*)_image)->Save(stream,&clsid,&eps)!=0) return 0;

		ULONG ws = 0;
		LARGE_INTEGER li;
		ULARGE_INTEGER npos;
		li.QuadPart = 0;
		stream->Seek(li,STREAM_SEEK_END,&npos);
		if(mem.Length()<npos.LowPart){
			mem.SetUseSysMemory(1);
			if(!mem.SetLength(npos.LowPart)) return 0;
		}
		stream->Seek(li,STREAM_SEEK_SET,0);

		HRESULT ret = stream->Read(mem.Handle(),mem.Length(),&ws);
		stream->Release();
		if(FAILED(ret)) return 0;
		return ws;
	}
Esempio n. 9
0
	int HttpRequest::Request(const void* data,int len,Memory<char>& html,String* retHead){
		if(!hRequest) return -1;
		if(!::HttpSendRequest(hRequest,NULL,0,(LPVOID)data,len)) return -1;

		DWORD dwSize = 0;
		if(retHead){
			HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &dwSize, NULL);
			if(dwSize!=0){
				retHead->SetCubage(dwSize/2);
				if(HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, (LPVOID)retHead->Handle(), &dwSize, NULL)){
					//安全起见,实际上数据已经是一个NULL结尾的字串。
					(*retHead)[dwSize/2-1] = 0;
					retHead->Realize();
				}
			}
		}

		int offset = 0;
		for(;;){
			char szData[1024];
			DWORD dwByteRead = 0;
			::InternetReadFile(hRequest,szData,sizeof(szData),&dwByteRead);
			if(!dwByteRead) break;
			if(html.Length()<dwByteRead+offset+1){
				if(!html.SetLength(dwByteRead+offset+1)){
					Print(L"html alloc failed");
					break;
				}
			}
			html.CopyFrom(szData,dwByteRead,offset);
			offset += dwByteRead;
		}
		if(offset!=0) html[offset] = 0;
		::InternetCloseHandle(hConnect);
		hConnect = 0;
		::InternetCloseHandle(hRequest);
		hRequest = 0;
		return offset;
	}
Esempio n. 10
0
	//class ImgEncode
	bool GetImageEncoderClsid(const wchar_t* type,CLSID* pClsid){
		static Memory<char> buffer;
		static UINT number = 0;
		Gdiplus::ImageCodecInfo* imageCodecInfo = (Gdiplus::ImageCodecInfo*)buffer.Handle();
		if(imageCodecInfo==0){
			UINT size = 0;
			Gdiplus::GetImageEncodersSize(&number,&size);
			if(!size) return 0;
			buffer.SetLength(size);
			imageCodecInfo = (Gdiplus::ImageCodecInfo*)buffer.Handle();
			Gdiplus::GetImageEncoders(number,size,imageCodecInfo);
		}
		Registry reg;
		if(!reg.Create(type,HKEY_CLASSES_ROOT)) return 0;
		String str(16);
		if(!reg.GetStrValue(L"Content Type",str)) return 0;
		for(UINT i=0;i<number;i++){
			if(WcsEqual(str,imageCodecInfo[i].MimeType)){
				*pClsid = imageCodecInfo[i].Clsid;
				return 1;
			}
		}
		return 0;
	}