|
Hi,
I've again a question about winsockets. How do I manage sending data, if I have e.g. TCHARs at my client side ? Do I have to convert my TCHAR strings at clientside to normal char strings, then send them, and then convert them at server side back to TCHARs ? Or is there a better way to do this ?
For information: I am writing a little protocol, so there are also Integers in my sending buffer...maybe this complicates the thing a little bit, I don't really know.
|
|
|
|
|
Sockets know nothing about the data you are sending. It's all just bytes at the socket level.
The only trick is to make sure you calculate BYTE counts and not TCHAR counts.
In other words, don't use _tcslen()....use _tcslen() * sizeof(TCHAR) (of course, add 1 to _tcslen()
for the NULL terminator if that's being sent).
|
|
|
|
|
Hey thanks. I've now done this at the sending client to copy the TCHARs to my sending buffer:
memcpy(pPointerToBuffer,MyString,wcslen(MyString)*sizeof(TCHAR))
And at the server side I do something like this:
int n = 10; //assuming that we know that this unicode string has a length of 10
TCHAR ReceivedString[n];
memcpy(ReceivedString,pPointerToBuffer,sizeof(TCHAR)*10);
...
This works and I think it's correct. Or is there a better way to do this ?
Again thank you
|
|
|
|
|
You need to make sure that your client and server both agree on what a TCHAR is. They both need to be compiled for UNICODE, or they both need to be compiled for ANSI.
Software Zen: delete this;
|
|
|
|
|
In addition to Gary Wheeler's response..
This line
memcpy(pPointerToBuffer,MyString,wcslen(MyString)*sizeof(TCHAR))
IMO could be confusing. wcslen() is for wchar_t types only, but TCHAR is generic and its type
depends on whether UNICODE is defined or not. For code that could potentially be compiled with
OR without UNICODE then I'd recommend using all generics:
// All generics
memcpy(pPointerToBuffer,MyString,_tcslen(MyString)*sizeof(TCHAR))
For code that will always be UNICODE compiled, use:
// All wchar_t
memcpy(pPointerToBuffer,MyString,wcslen(MyString)*sizeof(wchar_t))
Whatever is best for your situation - the point is consistency (makes it easier to prevent or
track down bugs later ).
As stated by Mr Wheeler, both ends will need to know the character type. That can be exchanged in
initial handshake between peers or it could be assumed (always the same). Both are fine - it's
a matter of what you need.
Along the same lines, you mentioned you have int or DWORD values you send as well. If you know
the CPU on both ends will always store "int"s in little-endian format then you can just send
them as a byte stream (byte count = sizeof(int)). If there's a chance the peers will use
different byte ordering then you'll want to convert them to network byte order (or whatever
scheme you choose to use) so that both ends will always be able to put an int back together
in the proper order.
All that aside, your code is fine for Unicode strings
|
|
|
|
|
Hey, thanks a lot. Now it's all clear to me. (sry for late reply)
|
|
|
|
|
Greetings
I'm building a website that has an automate engine to display pictures. There is a menu that lets you choose the event. The directories are organized like this:
- root
-- Weddings
--- WBlaBla1
---- Pic1
---- Pic2
---- PicN
--- WBlaBla2
---- Pic1
---- Pic2
---- PicN
--- SomeOtherTypeOfEventWithTheSameStructureHasPreviously
-- SomethingElse
The purpose is to sell the pictures, so it will have a cart shop. The problem is that I have the pictures in very high resolution, and I want to prevent the users from accessing the pictures in this format (i.e. 1807x1772). I know that PHP can handle this (i.e. display thumbnails) but the thing is that, with time, the events will be more and more, and this consumes space in the server, and the space is rented, offcourse.
So I had the idea of writting a C++ application that converts ALL the pictures in a directory to a low resolution version AND with a water mark, that way the sysadmin could convert the pictures before uploading them to the server. What I would like to ask is how to do this in C++, I mean, not search the pictures nor that sort of things, but how to lower the resolution and add the water mark to them. The pictures are all in JPG format.
Best regards
hint_54
|
|
|
|
|
Th easiest way I know of (on Windows) is to use GDI+ to load and save the images. A simple
stretchblt to a smaller, proportioned size is all that's necessary...load, resize, and save.
|
|
|
|
|
I'll take a look thx
hint_54
|
|
|
|
|
Here ya go...a holiday present
(I ripped the GetEncoderClsid() right out of the GDI+ docs
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0;
UINT size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1;
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
...
Gdiplus::Bitmap SrcBitmap(L"D:\\Source\\Images\\sony-cybershot.jpg", FALSE);
Gdiplus::Bitmap DstBitmap(320,240,SrcBitmap.GetPixelFormat());
Graphics DstGraphics(&DstBitmap);
DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240);
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid);
DstBitmap.Save(L"D:\\Source\\Images\\sony-cybershot_test.jpg", &jpgClsid, NULL);
|
|
|
|
|
Djii thx !!
hint_54
|
|
|
|
|
I downloaded the Apache Portable Runtime for windows. It included a
VC6 solution and project definitions. I loaded the soultion with Visual Studio 2005 and it successfully converted the solution and project to
the new format. I can compile the code with the converted solution.
I decided to create a new solution from scratch. But when I compile my
solution it finds the wrong include file. In my configuration I specify
an include search string of:
".\include; .\include\arch; .\include\arch\win32; .\include\arch\unix"
The include in question, "apr_arch_file_io.h", exists in the "win32" and
"unix" directories. but the compiler loads the one in the "unix" directory.
I do not understand why the converted solution works and mine does not.
If I remove the include from the "unix" directory then my solution
compiles cleanly.
Any thoughts as to what configuration option I have to set to my solution to work. I have looked at the converted project defintions but
nothing obvious stands out.
Thanks for any help
James Johnson
|
|
|
|
|
One thought only: look at the preprocessor directives for the converted project and in the code. When cross platform code is involved you normally insert ‘#ifdef’ statements in the code to specify which platform you are compiling for.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I'm writing a directx program to display some primatives and I'm just wondering is there a way to query windows on how much memory you're using.
|
|
|
|
|
Windows has GlobalMemoryStatus() and GlobalMemoryStatusEx(). About as useful as the task
manager
There's some useful stuff in The CRT Debug Heap[^]
I'm sure there's others....these just come to mind immediately.
|
|
|
|
|
Hi, could someone point me in the direction of tutorials or articles about how to port C++ code from Windows CE to Windows XP? Also any pointers or tips on things to be careful with or watch out for while doing this would be greatly appreciated.
Thanks!
KR
|
|
|
|
|
I know nothing about CE programming other than it is a subset of Windows and therefore it should require almost no changes, if any, to port it. The complications would normally occur if you were trying to go the other way. If you can not run it on the desktop Windows platform, then you should look at the main entry routine (function/method), because that is where the problem would most likely lay.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I was wondering if anyone knows of a fairly transparent way to compress resource data (icons mainly). I've googled, but so far I haven't found anything.
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
Is this even possible? If you compressed the icons, how would the system know to first uncompress them before using them? I guess you could compress the icons, and then store them as RT_RCDATA . When you need them, just reverse the process.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I was thinking about some kind of scheme which could decompress the resource sections, and then replace the compressed data with the uncompressed data.
I found something that will do it for me, but differently: UPX[^]. Works quite well!
If you take a look at the compressed PE with a resource explorer, you'll see that it has compressed the data, which it'll replace during inflation of the "real" exe (except for the version section, first icon entry, and type libraries). I managed to shrink my exe to less than a third of its original size (icon resources - ). Didn't detect any significantly higher load time.
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
I've had good luck UPX too, but one thing to watch out for is using it on a DLL that will be loaded by some method other than LoadLibrary() , such as res:// . If it will be loaded like that, you can't compress the resources or else Bad Things will happen.
|
|
|
|
|
That's because it loads the DLL without calling DllMain(), right? Thanks for the heads up on that one. I have a DLL which I'm using with res://!
--
From the Makers of Futurama
|
|
|
|
|
That's my guess - if something loads the DLL with LoadLibraryEx(LOAD_LIBRARY_AS_DATAFILE) then DllMain() isn't run, and the unpack-on-the-fly code isn't run either.
|
|
|
|
|
hi all,
I am not able to use the ClipBoard Functionality of vc6.0 in VC7.0.
For Example the ClipBoard Functionalities like
::OpenClipboard(...),::SetClipboardData(...) etc.
Presently i am migrating the VC6.0 to VC7.0 in UnManged Code. Consider that it is not a Managed Code but it is Unmanaged Code in VC7.Net Version.
Please help me out.
Uday kiran
|
|
|
|
|
uday kiran janaswamy wrote: I am not able to use the ClipBoard Functionality of vc6.0 in VC7.0.
What errors you are getting ?
|
|
|
|