|
Thanks for the bit shift example.
The binary data will eventually get displayed on the screen but we will also be processing the data depending on what type it was originally (i.e. integer, sound, etc...), so if you could give me an example of how to do both types that would be great.
cheers,
Andy
|
|
|
|
|
// given a 16-bit WORD (unsigned short)
WORD wHiLow;
// reverse the two bytes in the word
WORD wLowHi = MAKEWORD( HIBYTE(wHiLow), LOBYTE(wHiLow) );
// obtain binary string
char szBuffer[32];
// binary is radix of 2
itoa(wLowHi, szBuffer, 2);
|
|
|
|
|
Hi All,
This may be a silly question, but how do you seek in a large file. I have to deal with file sizes of 3GB to 5GB and my programme currently uses the C-runtime fopen, fread, fseek, ftell, etc. But with files that large the sizes are beyond the size of 'long' that these functions use. Are there ways around this? (The programme has to run on Win98 - WinXP) I need to be able to get the size of the file, and be able to seek to different parts of it.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Try Windows API,
GetFileSize
Support 64 bits file size
|
|
|
|
|
Thanks, this looks good
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
I don't have any sample code for you.
But to manipulate large files, you should throw C functions away, and
use Windows API to do it, open, seek, get file size, read/write, etc.
It's not difficult to learn those APIs by yourself.
|
|
|
|
|
Koms Bomb wrote:
It's not difficult to learn those APIs by yourself.
Okay, just one question:
C-Runtime provide feof, what is the windows API version of this?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
C-Runtime provide feof, what is the windows API version of this?
When using ReadFile() , consider this from MSDN:
If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation. However, if the file was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the return value is FALSE and GetLastError returns ERROR_HANDLE_EOF when the file pointer goes beyond the current end of file.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi David,
Thanks for the info
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Another way,
GetFileSize to get the file size,
Then use SetFilePointer to 'seek' the file pointer, but you should only seek with zero offset from currect point, then that API will tell you where the currect pointer is.
Now compare that pointer with the file size...
So you don't need to read to the end of the file.
|
|
|
|
|
I've not ever used FAT32, but it supports a maximum file size of 232-1 bytes. That would prohibit your 5GB file from working on Windows 98.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi David,
You are quite right. That's why the C-runtime calls were working well as you could seek 2GB - 2 distance. But now with XP/2000/NT we have the problems.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
And for whatever it is worth, if you install the C runtime library source code and trace through it far enough, you will find it just ends up mapping all the standard C file flags and functions into calls into the Win32 API anyways.
I had to use that as defense to the argument when someone tried to tell me the C runtime was faster than the Win32 API - how could it be, after a slew of mapping operations, the C runtime functions ended up calling the Win32 API functions anyways...
|
|
|
|
|
Hi Everybody,
In my rich edit application, I just discovered CFM_LINK and am enjoying having clickable links in my CRichEditCtrl. However, when I use streamOut and streamIn to save my control contents to disk and back, all the RTF formatting is preserved except for the links. Please guide me how to save the RTF document along with the hyperlink.
Regards,
Prakash.
A Journey of thousand miles must begin with a single step.
|
|
|
|
|
XP, no SP, the WMP is the one binds with XP.
I put a WMP control on a MFC dialog, then I play it, and adjust the volume.
I want to save the volume when exits, so I tried GetVolume, but it always
returns -600 (the default volume value).
Why? What have I missed? Did any one experience this?
I've post this in MS newsgroup, but got no answers.
Thanks.
|
|
|
|
|
Can you provide some code?
P.
|
|
|
|
|
Sorry, the code is in my home and I'm in office now.
My steps are,
1, Right click on th dialog then select Insert ActiveX control,
2, Select Windows Media Player and put it on the dialog,
3, Run the app and play something,
4, When a button click, I call the Medial Player's GetVolume to get the volume, but the result is always -600 even I've change the volume bar.
|
|
|
|
|
I am receiving a binary buffer in big endian on a little endian machine.
Is there an SDK func that can convert big buffers from big endian to little endian???
Thx for any help,
Greetings,
Davy
|
|
|
|
|
Hi Davy,
I don't know of a SDK to do it, but switching endian's isn't a big deal. You can do the following:
<br />
typedef struct _tagByteBreak<br />
{<br />
unsigned char bUpperByte;<br />
unsigned char bMiddleByte1;<br />
unsigned char bMiddleByte2;<br />
unsigned char bLowerByte;<br />
} BYTE_BREAK;<br />
<br />
typedef union _tagEndianSwitch<br />
{<br />
BYTE_BREAK stBreak;<br />
unsigned long int ulFull;<br />
} ENDIAN_SWITCH;<br />
<br />
void UTIL_SwitchEndian (unsigned long int *pulIn)<br />
{<br />
ENDIAN_SWITCH Endian;<br />
unsigned char btemp;<br />
<br />
Endian.ulFull = *pulIn;<br />
<br />
btemp = Endian.stBreak.bLowerByte;<br />
Endian.stBreak.bLowerByte = Endian.stBreak.bUpperByte;<br />
Endian.stBreak.bUpperByte = btemp;<br />
btemp = Endian.stBreak.bMiddleByte1;<br />
Endian.stBreak.bMiddleByte1 = Endian.stBreak.bMiddleByte2;<br />
Endian.stBreak.bMiddleByte2 = btemp;<br />
<br />
*pulIn = Endian.ulFull;<br />
}<br />
This code takes a unsigned long int (32-bits) at swops the endian (either direction). Now all you need is a loop:
<br />
void ConvertEndian (unsigned long int szLen, unsigned long int *pulBuf)<br />
{<br />
for (unsigned long int i = 0; i < szLen; ++i)<br />
{<br />
UTIL_SwitchEndian (&pulBuf[i]);<br />
}<br />
}<br />
This will convert the buffer to the opposite endian system. It should be easy to modify for 16-bits.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Thanks for the thorough answer!
Greetings,
Davy
|
|
|
|
|
You have to know the layout of the buffer.
If it is just an array of numbers than you do something like what Richard suggests.
More often though the buffer is the contents of a struct or class.
In that case you have to swap the members.
e.g.
struct ST {
long l;
short s;
float f;
double d;
};
You get a buffer:
char *buff = ...;
Cast buffer to structure:
struct ST *st = (struct ST*)buff;
Swap members:
st->l = SWAP4(st->l);
st->s = SWAP2(st->s);
st->f = SWAP4(st->f);
st->d = SWAP8(st->d);
where SWAP*() swaps the specified number of bytes.
e.g.
#define SWAP2(x) ( ((x) << 8) | ((x) >> 8) )
#define SWAP4(x) ( ((x) << 24) | ((x) >> 24) | \
( ((x) & 0x0000ff00) << 8 ) | \
( ((x) & 0x00ff0000) >> 8 ) \
)
#define SWAP8(x) ( ((x) << 56) | ((x) >> 56) | \
( ((x) & 0x000000000000ff00) << 40 ) | \
( ((x) & 0x0000000000ff0000) << 24 ) | \
( ((x) & 0x00000000ff000000) << 8 ) | \
( ((x) & 0x000000ff00000000) >> 8 ) | \
( ((x) & 0x0000ff0000000000) >> 24 ) | \
( ((x) & 0x00ff000000000000) >> 40 ) \
)
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi!
I'm having trouble using this API callback function, EnumSystemLanguageGroups.
When I compile I get this error message:
c:\Documents and Settings\bsosla\Desktop\Regional Settings Plugin\Regional Settings\Regional Settings\regionalSettingsPlugin.cpp(457): error C3861: 'EnumSystemLanguageGroups': identifier not found, even with argument-dependent lookup
Reading a little about this callback function I see that I have to include winnls.h and windows.h, adding the library kernel32.lib.
All this is done but without any results.
What am I doing wrong?
Thanks!
|
|
|
|
|
Hachaso wrote:
...error C3861: 'EnumSystemLanguageGroups': identifier not found, even with argument-dependent lookup
This is not a Visual Studio v6 error. Are you using Visual Studio v7.x instead?
Have you seen this?
Hachaso wrote:
Reading a little about this callback function I see that I have to include winnls.h and windows.h...
Actually, only winnls.h is required. You get that one by default if you are already including windows.h .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi!
Thanks for helping me!
I'm using Visual Studio .NET 2003. I guess that its version 7.
Do you think that the problem can be related to what kind of project I've started?
When I create a Win32 project, letting the Wizard create the base code, then add my lines I get no compile error. But adding the same lines to another existing project returns an error. This is why I'm wondering if it has to do with what kind of project I start?
Thanks!
|
|
|
|
|
At this point, I would compare the project settings of the one that works with the one that doesn't work.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|