|
Thanks Mr. Baken
i wrongly typed 4 bit. It was 4 byte number. Should i just use a long int to get data and it will automatically get 4 bytes from a file or i would have to do something else.
Thanks
Aqueel Ahmad Mirza
We Believe in Excellence
-- modified at 5:13 Tuesday 1st November, 2005
|
|
|
|
|
Hi there!
I suspected you wanted an integer, that's why I put an '?' in the text.
You can use either an unsigned int or an unsigned long, they both are 32 bits (== 4 bytes) long (in Win32/VC++).
I suggest You use unsigned int.
But beware! The value can be stored in two different ways, depending on the CPU that wrote the file (or the specs of the file). Little endian and Big endian. Intel CPU's use little endian, Motorola CPU's (Macintosh) use big endian.
If you want to know more about endianness, Google for "endian intel motorola"
So if the value you get is incorrect, the file is written using big endian. Then you will need to convert the value you read to little endian.
Here is a function that will do that for you. Call it only if you need it:
<code>
void SwapInt(void* ap)
{
unsigned char* p;
unsigned int a;
p = (unsigned char*) ap;
a = (unsigned int) p[0];
p[0] = p[3];
p[3] = (unsigned char) a;
a = (unsigned int) p[2];
p[2] = p[1];
p[1] = (unsigned char) a;
}
Usage:
unsigned int ui;
ui = <something>;
// Now convert ui from big endian to little endian
SwapInt(&ui);
// Now ui is in little endian
</code>
-- modified at 7:14 Tuesday 1st November, 2005
|
|
|
|
|
Do you know that you can give score (points) to answers that has been helpful to you?
Have a look in the lower right corner, click on a number, the higher, the more appreciated...;)
-- modified at 6:58 Tuesday 1st November, 2005
|
|
|
|
|
I am doing a project to change computer name which is in the domain. I tried many way but all failed.
First, I used NetRenameMachineInDomain function, function return succeeded, and the computer name changed. But it isn't in domain again.
Then, I tried to change computer name, then use NetJoinDomain function. Function return succeeded again, but the computer is not in domain.
Computer name after changed shows ComputerName.DomainName.com, that is correctly, but there is not "DomainName\Domain Admins" in local Administrators group. I can't logon the computer by the domain user, so I think the computer is not join in the domain really.
How can I do or there is another step I must do after use NetJoinDomain function?
Pls help me!
Thanks a lot.
RickPan
|
|
|
|
|
hi
i want add an image to vc++ project with Transparent mode.
please help me.
|
|
|
|
|
|
Hello
I am working with binary files in c++. What i am doing is that i am reading at every 5th position in a binary file. if there is 0 then break the loop.
I wrote the following code
what is error in it. I wrote 1 at the start of the file. But it is not showing that 1
Code is
int i = 0;
int count = 0;
ifstream fin("data.bin", ios::in | ios::binary);
while (count != 5120)
{
fin.seekg(count);
cout <<i<<' ';
="" fin.read((reinterpret_cast="" <="" char="" *="">&i, sizeof(i));
if (i == 0)
break;
count+=5;
}
Please reply...
Thanks>
Aqueel A. Mirza
We Believe in Excellence
-- modified at 1:26 Tuesday 1st November, 2005
|
|
|
|
|
Hello.
You are reading sizeof(i) no of charaters from the file. Is that what you want?
i is an integer, so sizeof(i) will evaluate to 4 (bytes).
My guess is that you really want to read one character at the time from the file and then interpret it as an integer, right?
The read it as an unsigned char, with sizeof(unsigned char)
Then, cast it to ant int.
|
|
|
|
|
How do I create a folder in the Program Files directory programatically? I haven't programmed in Win32 the last few years and don't have my win code to refresh my memory. I know it is some COM object function that gets the special location like Trash, Program Files, History..
Thanks in advance.
|
|
|
|
|
LPITEMIDLIST pid;<br />
HRESULT hr;<br />
hr = SHGetSpecialFolderLocation(m_hWnd,0x0026,&pid);<br />
<br />
TCHAR path[MAX_PATH];<br />
SHGetPathFromIDList(pid,path);<br />
<br />
LPMALLOC mal;<br />
SHGetMalloc(&mal);<br />
mal->Free(pid);
I hope it works, and is without errors.
this is this.
|
|
|
|
|
I have used the MFC application wizard in Visual C 6.0 to create a FormView application. The resultant FormView contain the word "Untitled" before the program name I supplied. What is an acceptable method of eliminating the word "Untitled"?
|
|
|
|
|
I believe SetWindowText on the main window is what you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
Put the following code in CMainFrame::PreCreateWindow
cs.style &= ~FWS_ADDTOTITLE ;
--
======
Arman
|
|
|
|
|
I'm trying to convert some hexadecimal values into japanese text and I can't figure how to do it. I know I have to use a char set that have the japanese chars like unicode and that japanese is multibytes, but i can't seem to find enough information about how i'm supposed to do it.
It would be awesome if someone could help me whit that.
|
|
|
|
|
U gotta use WideCharToMultiByte and MultiByteToWideChar.
If u tell me the exact format of the input I'll be able to tell u the exact process of decoding.
|
|
|
|
|
I'm reading from a binary file each hexadecimal byte that i put into an integer, and i was converting them into a wchar, and trying to put 2 byte together, but that didn't really work. And finally i was displaying them into a textbox. And I also want to do the reverse process.
|
|
|
|
|
Lets make a little test - u create a little file from what u got, save with the extension .txt, drop it into IE and play with the encoding - try unicode/japaneesse/...
If u can't make it show something u probably did something wrong in decoding the file.
|
|
|
|
|
I managed to display japanese chars, but it's not the good char that is displayed.
could you help me on how to start from 2 separated bit of hexadecimal and put them together correctly to display the good japanese char.
|
|
|
|
|
Hi
I have written some MFC Code - But its not working on all machines !!!
<br />
...<br />
#include "device.h"<br />
#include "receiver.h"<br />
...<br />
#include "MyAppView.h"<br />
<br />
<br />
....<br />
<br />
class CDEVICE<br />
{<br />
public:<br />
...<br />
virtual void doA()=0;<br />
virtual void doB()=0;<br />
virtual void doC()=0;<br />
...<br />
}<br />
<br />
class CRECEIVER : public CDEVICE<br />
{<br />
public:<br />
...<br />
virtual void doA();<br />
virtual void doB();<br />
virtual void doC();<br />
...<br />
}<br />
On some XP machines I retrieve an error after returning from doA()
I debuged with DRWatson
<br />
6036719d 33c9 xor ecx,ecx<br />
6036719f eb03 jmp MyApp+0x771a4 (603671a4)<br />
FEHLER ->603671a1 8b4e1c mov ecx,[esi+0x1c] ds:0023:3034324c=????????<br />
603671a4 ff742410 push dword ptr [esp+0x10]<br />
603671a8 50 push eax<br />
And the Corresponding MAP file delivered
<br />
0001:000760ea ?ActivateTopParent@CWnd@@QAEXXZ 603670ea f nafxcw:wincore.obj<br />
<big> 0001:00076127 ?GetTopLevelFrame@CWnd@@QBEPAVCFrameWnd@@XZ 60367127 f nafxcw:wincore.obj</big><br />
0001:00076168 ?GetSafeOwner@CWnd@@SGPAV1@PAV1@PAPAUHWND__@@@Z 60367168 f nafxcw:wincore.obj<br />
0001:00076186 ?MessageBoxA@CWnd@@QAEHPBD0I@Z 60367186 f nafxcw:wincore.obj<br />
So there should be an error in or at
GetTopLevelFrame
can this be true ??
And/OR how to determin the exact error position ??
Any Idear might help Please !!
THX Tim
|
|
|
|
|
I meant error at
<br />
ActivateTopParent<br />
....
Tim
|
|
|
|
|
I'm going to totally wing it and guess that you are calling an instance of CDevice before the main window is actually done being created. The solution is to have the OnCreate message initialize communication with CDevice.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi
No ... Sorry ...
CDEVICE is initialised in the myAppView Constructor, but the work starts after clicking a menu buttom
for example:
<br />
void startWork()<br />
{<br />
doA();<br />
doB();<br />
doC();<br />
}<br />
or
<br />
void startWork()<br />
{<br />
doB();<br />
doA();<br />
doC();<br />
}<br />
I tried all combinations the error allways comes at returning from doA() ??!??!!
Any suggestions ?
Tim
|
|
|
|
|
FILE *Ofile;
<br />
int fCnt = 0;<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",fCnt);<br />
while ((Ofile = fopen(gz_op_fname, "r")) != NULL)<br />
{<br />
sprintf(gz_op_fname,"TargetStatistics%d.txt",++fCnt);<br />
fclose(Ofile);<br />
}<br />
I have the above code to create a file TargetStatistics%d.txt.
ie. if TargetStatistics0.txt, TargetStatistics1.txt already exists, then TargetStatistics2.txt will be created.
But sometimes with this code I get Invalid handle exception in the while loop.
and I occurs often when there are more files, say it has to create TargetStatistics20.txt.
Whats the problem here. Thanks in advance.
|
|
|
|
|
Which line do you suppose is going to create the file within yor piece of code?
SkyWalker
|
|
|
|
|
oops..sorry I didnt include the part of code that creates the file.
But the exception is surely occuring in the while loop that I had shown in my previous post, for i checked with outputdebug messages. I also included a debug message inside the while loop, and every time its happening after TargetStatistics5.txt or TargetStatistics6.txt.
Thanks.
|
|
|
|