|
My TCP/IP program transfers large data between client/server frequently.
I want to compress data to reduce transferring amount and increase transferring speed.
So I need simple, fast and efficient source code to compress/decompress data, winzip is too slow because it considers many things, which are useless for me, such as file structure.
Do you know any fast compressing source code other than winzip?
Thanks for links or suggestions.
|
|
|
|
|
The only thing I know of is zlib, which also uses the deflate algorithm to compress data. But really the thing that gives you the most control over the speed of the compression is how highly compressed you want it. I think zlib gives you a range of 1-9 for speed vs compression where 1 is the fastest but results in the largest size and 9 gives the smallest size but at the cost of time.
I think though, that if you do some quick checks on the data you want to compress then you can save some time yourself, JPEGs and PNGs are already compressed for example so it would be a waste of time to try and compress that data, and you would be better to just send it as-is.
|
|
|
|
|
|
I have two different applications appDad and appKid. appDad is a Windows Forms Application and it calls appKid.exe. appKid does a series of prinf´s that I want to display in a text box in appDad.
Some suggest that I use FILE * output = _popen ("ls", "r") or freopen ("/dev/tty", "w", stdout) but I´m not quite sure what I´m doing.
Am I being lazy for asking instead of researching a bit more? I hope not...
|
|
|
|
|
See here and here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Ok, thanks a lot. But... is there a simpler way to do it in .NET?
|
|
|
|
|
piul wrote: But... is there a simpler way to do it in .NET?
.NET is a framework, not a language. If you are referring to Managed C++, see here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
How to get a CBitmap from a LPDIRECTDRAWSURFACE7 ?
modified on Thursday, January 27, 2011 10:10 AM
|
|
|
|
|
Try something like this:
1. Use IDirectDrawSurface7::GetSurfaceDesc[^] to get the dimensions of the surface.
2. Use IDirectDrawSurface7::GetDC[^] to get a device context for the surface
3. Use CBitmap::CreateCompatibleBitmap[^], specify the DC you got from the surface, you might use CDC:Attach[^] to get a CDC from the HDC, just don't forget to also Detach it before releasing the DC. The dimensions for your bitmap you got in step 2.
4. Create a DC compatible with the surface DC using CDC::CreateCompatibleDC[^]
5. Select the bitmap you created in step 3 into the DC you created in step 4. Do a bit-block-transfer with CDC::BitBlt[^] to move the pixel data from the DC you got in step 2 to the DC you got in step 4.
6. Deselect the bitmap (3) from the DC (4), destroy the DC (4)
7. Use IDirectDrawSurface7::ReleaseDC[^] to free up the DC you got in step 2.
8. Live happily ever after.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Hi thx for the awnser.
I haven't got it to work yet a get an assertion error when calling CreateCompatibleBitmap()
Not sure I do the right thing when geting CDC object.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pCDC);
dcMemory.SelectObject(cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,pCDC,0,0,SRCCOPY);
pCDC->Detach();
dcMemory.Detach();
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
|
|
|
|
|
Instead of this:
kagelind wrote: CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
do this:
CDC surfaceCDC;
surfaceCDC.Attach(surfaceHDC);
Use &surfaceCDC everywhere you used pDC.
Then instead of this:
kagelind wrote: pCDC->Detach();
do this:
surfaceCDC.Detach();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
also, instead of this:
kagelind wrote: CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
do this:
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&surfaceCDC, SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
and use &cBmp everywhere you need its address.
Also, when you select the bitmap into the dcMemory, store its old CBitmap and select it back into the memory DC before destroying it or you might end up leaking handles. So something like:
CBitmap *originalBmp = dcMemory.SelectObject(&cBmp);
...do what you need...
dcMEmory.SelectObject(originalBmp);
dcMemory.DeleteDC();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
The code runs now but don't seems to work.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC SurfaceCDC;
SurfaceCDC.Attach(sourceHDC);
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(&SurfaceCDC);
CBitmap * orginalBmp = dcMemory.SelectObject(&cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,&SurfaceCDC,0,0,SRCCOPY);
SurfaceCDC.Detach();
dcMemory.SelectObject((HBITMAP)orginalBmp);
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
If I try to save the CBitmap a get an assertion error. It looks like the HBITMAP is NULL
CImage saveImage;
saveImage.Attach(cBmp);
saveImage.Save(_T("test.bmp"));
saveImage.Detach();
|
|
|
|
|
Does this succeed:
kagelind wrote: cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
?
This:
kagelind wrote: dcMemory.SelectObject((HBITMAP)orginalBmp);
is completely wrong, it should be:
dcMemory.SelectObject(orginalBmp);
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
|
Glad it works.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
I want to study how to write my compiler, so need a open source compiler for study.
The GCC is too big. is there simple compiler?
|
|
|
|
|
Have a look at:
- LCC[^] (consider buying the book).
- TCC[^].
A nice reading (oldie-goldie) is Let's Build a Compiler - by Jack Crenshaw[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I can strongly recommend that you read the Dragon Book[^]. Writing a compiler is both simple and really complex at the same time. This book guides you through language definition, lexical analysis, syntax analysis and finally code generation. It also has advanced sections for related technologies.
With this book as a guide, writing a simple compiler from scratch is not too much work, and gives a great understanding of languages and compilers. This is not really an answer to your question, but still...
|
|
|
|
|
I am currently trying to convert a string that resides in a _bstr_t variable vFieldDate into a char array. I have found that I can type cast this via the (char *) with a variable I named holder which is a pointer to a char. The issue I am having a hard time solving is how to convert this to a char that can be stored within the char Date[ARR]. When I attempt the following code I get the compilation error "Cannot Convert From Char * to Char. How do I extract the value that resides in the holder location and save it into the array?
Date[cyc] = holder;
The below portions of code are a part of an ADO program that is accessing data from a database.
char Date[ARR] = {};
_bstr_t vFieldDate;
vFieldDate = rec->Fields->GetItem("Date")->Value;
char *holder = (char*)vFieldDate;
|
|
|
|
|
This question has been anwered with:
#include <cstring>
//...
strcpy( Date, holder );
|
|
|
|
|
This will only work if he is using a wide string, in which case it would be wcscpy because BSTR is a wide string.
To copy a BSTR into an ASCII string, you will need to convert the character set.
|
|
|
|
|
Disregarding the method of conversion, the assignment you used attempts to assigns an array of characters to single character: Date is defined as an array of ARR characters, and Date[cyc] denotes the character with the index cyc within that array.
What was your intention? I suspect that what you really wanted is to define Date as an array of strings rather than as an array of characters. In this case you should define Date as char* Date[ARR]; .
On a sidenote, what you are trying to achieve is like pouring milk into a crate for beer bottles: you can't just go ahead and assign the contents of one variable to another variable that is designed to hold something completely different - doing this will usually result in spilling the contents. Instead you have to use the proper function or method for transfering the contents of one variable into the other. Plus you might need to allocate proper containers first: so first thing, pick up an empty beer bottle, then pour the milk into it, and only then you can put that bottle into the crate.
With respect to these strings, the Date array corresponds to the crate for beer bottles. The beer bottles correspond to char-strings, and the milk corresponds to the contents of that _bstr_t. So what you have to do is:
- allocate an array of char, big enough to hold the _bstr_t
- call the appropriate method to convert a _bstr_t into a char*, and then
- put it into the Date array.
|
|
|
|
|
Hello
I have some trouble interpreting a string and I hope you can help me.
I have to convert a string, or a word in a number. Like five hundred fifty in 550. I dont know exactly how to do it.
I was thinking to try to analize each word, but this seems like a huge code. Or i was thinking that maybe you can check in a table, but then the table should be huge(numbers should go up to millions)
Is there a smarter way? What do you suggest?
Thank you very much
|
|
|
|
|
There is a simpler way of doing it. In fact if you google it, you will see many examples on the web. Here [^] is one such example.
|
|
|
|