|
This should work:
// here's the bit-shifting stuff!
#define SH(p) ((unsigned short)(unsigned char)((p)[1]) | ((unsigned short)(unsigned char)((p)[0]) << 8))
#define LG(p) ((unsigned long)(SH((p)+2)) | ((unsigned long)(SH(p)) << 16))
void main( int argc, char *argv[] )
{
FILE *pFile;
unsigned char uBuffer[1024];
long lWidth,
lHeight,
lSize;
pFile = fopen(argv[1], "rb");
if (NULL != pFile)
{
fread(uBuffer, sizeof(unsigned char), 8, pFile);
fread(uBuffer, sizeof(unsigned char), 4, pFile);
// convert this to a long
lSize = (uBuffer[0] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[1] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[2] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[3] & 0xff);
fread(uBuffer, sizeof(unsigned char), 4, pFile);
fread(uBuffer, sizeof(unsigned char), lSize, pFile);
lWidth = LG(uBuffer);
lHeight = LG(uBuffer + 4);
fclose(pFile);
}
}
|
|
|
|
|
Hi,
I'm having a frustrating little problem with 64-bit integer arithmetic. It goes something like this:
0xba5da800 * 0x38E
which should equal:
0x29678EB3000
Unfortunately, the code is a bit like this:
#define unsigned __int64 uint64_t<br />
<br />
unsigned long myval = 0xba5e3500;<br />
<br />
uint64_t myfunction(unsigned long val)<br />
{<br />
return val * 1000;<br />
}
This doesn't work, nor does:
return ((uint64_t)val * (uint64_t)1000);
or
return (uint64_t)((uint64_t)val * (uint64_t)1000);
The value I get returned looks like:
0xfffffeefffff0800 (or similar)
Now, I've run into problems before with not casting everything into __int64 twice (ok I exadurate slightly) for every calculation - but this is weird. It seems that casting val to uint64_t is turning it into:
0xffffffffba5e3500
Why is this happening?!
I truly do hate __int64, any help would be appreciated.
thanks,
Simon
--
Simon Steele
Programmers Notepad - http://www.pnotepad.org/
|
|
|
|
|
I get the desired results with:
typedef unsigned __int64 uint64_t;
unsigned long myval = 0xba5da800;
uint64_t myfunction(unsigned long val)
{
return (uint64_t) val * (uint64_t) 0x38e;
}
void myotherfunction()
{
TRACE("%I64u\n", myfunction(myval));
}
|
|
|
|
|
Check your tests?
The second two should work fine. The first one fails because the values are multiplied as longs and then returned as a uint64. The multiplication as a long wraps. Casting one value to a uint64 will make the multiplication occur on uint64's and should give correct results.
Your message mentions 0xba5da800 * 0x38E = 0x29678EB3000 at the top and your tests use 0xba5e3500 * 1000...
The code below seeems to give the results you expect.
typedef unsigned __int64 uint64_t;<br />
<br />
unsigned long myVal = 0xba5da800 ;<br />
<br />
uint64_t myfunction1(unsigned long val)<br />
{<br />
return val * 0x38E;<br />
}<br />
<br />
uint64_t myfunction2(unsigned long val)<br />
{<br />
return ((uint64_t)val * (uint64_t)0x38E);<br />
}<br />
<br />
uint64_t myfunction3(unsigned long val)<br />
{<br />
return (uint64_t)((uint64_t)val * (uint64_t)0x38E);<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
uint64_t result1 = myfunction1(myVal);<br />
uint64_t result2 = myfunction2(myVal);<br />
uint64_t result3 = myfunction3(myVal);<br />
<br />
printf("myfunction1 - 0x%I64x\n", result1);<br />
printf("myfunction2 - 0x%I64x\n", result2);<br />
printf("myfunction3 - 0x%I64x\n", result3);<br />
<br />
return 0;<br />
}
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Hi,
thanks for saying that it works for you, it led me to the problem. The value being passed in was actually a long not an unsigned long, I didn't notice because it's actually part of a structure the definition of which has changed.
"it does work, you fool!" posts are just as useful as solution advice so thanks to those who replied. I'll write a test harness next time before posting, my bad
thanks again,
simon.
--
Simon Steele
Programmers Notepad - http://www.pnotepad.org/
|
|
|
|
|
Hi everybody.I want programmaticly to change or set the 'Author' property for the newly created file.Any help will be appreciated.
|
|
|
|
|
Re: Changing file properties DavidCrow 15:30 7 May '03
Use the CFile::SetStatus() method, or use SetFileAttributes().
here you go, btw search forum before posting
Greetings
Jens
|
|
|
|
|
Unfortunately, those do not work with compound properties.
|
|
|
|
|
CFileStatus has not field Author.I think it is not suit for this case.But thank you anyway.
|
|
|
|
|
While it's not exactly what you are after, see if MSDN article Q186898 is of any help.
|
|
|
|
|
This example explaines about compound file whereas i need for text file.
|
|
|
|
|
It'll work with "regular" files, too. You just have to use StgOpenStorageEx() instead of StgOpenStorage().
|
|
|
|
|
Hi
I want to center the title text of my application (mfc) in the title bar.
Now it is positioned left.
Anyone can help?
Greetings
Jens
|
|
|
|
|
Good question. I suspect it's somewhat difficult, if it's even possible. You might end up creating a caption-less dialog (i.e., a dialog without the WS_CAPTION style), and then drawing your own caption in the client area of the dialog.
|
|
|
|
|
Good question....
Thank you for the appreciation
I'll see if i can fix the problem. If i have working code, i'll send it to you or post it somewhere on forum here.
Best regards
Jens
|
|
|
|
|
i hav some idea..
title bar length = widhth of ur dialog/window
u alos get the indent/width of the text
then find the half of width
find the haif of string
place the string from halfof titlebar - half of text
you can add the spaces in fornt of the string to place the text in the appropriate position.
hope u got it..
CodeTheDreams();
|
|
|
|
|
This is the way I would do it as well.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I have not done it... never...
but...
1.filling the beggining of the string with spaces is not good if you change the font... because spaces size and font size changes also.
2.Deleting the caption and placing a label centered... is also a not standard thing that will make your app. to seem strange...
3.I'm sure that I've seen here in CP some pieces of code that show how to paint over the Caption bar (the typical thing of adding additional buttons and so on...).
I think that the best approach would be to leave the caption text blank and painting the desired text calculating the width of the text that will be displayed in pixels and...
Take a look at the articles that show how to draw in the caption bar...
then you can search for how to find the width of a outputted text via GDI calls.
then it's only a matter of time, dividing in order to get the coordinate where to start painting and so on...
Well, I have not done this and this is only theory, but it sounds good to me...
PS:
my english is not my best...
Hope this helps...
|
|
|
|
|
Hi,
there was a working code on the net called "shadcap", originally written by "Paul DiLascia", Q&A author of MSJ Magaizine. Please search it on the net. Actually, I downloaded the code, just few days back. I couldnt find the link now. Please search it on the net. Otherwise, I can send u the code.
|
|
|
|
|
Hi,
As, other members were suggested, its bit of complex coding.
If you really want to do it, here is the link, and
download "C++0697.exe"
http://www.microsoft.com/msj/0697/c0697.aspx
regards
~Hari~
|
|
|
|
|
Hi All!
Here goes the question:
Mr. C++ has cleary descibed how to use function objects in Parhagraph 18.4 of his Book. The
Sample code works OK, and if i use them with STL, everything`s OK
Here is a simple sample:
void Add7(int& out_Int)
{
out_Int += 7;
}
class AddNumber
{
public:
int m_iToAdd;
AddNumber(int in_iToAdd = 0)
{
m_iToAdd = in_iToAdd;
}
void operator()(int& out_Int)
{
out_Int += m_iToAdd;
}
};
class A
{
public:
std::vector < int > m_vData;
};
void main()
{
A tmp_a;
tmp_a.m_vData.push_back(7);
tmp_a.m_vData.push_back(5);
tmp_a.m_vData.push_back(6);
std::for_each(tmp_a.m_vData.begin(),tmp_a.m_vData.end(),Add7);
std::for_each(tmp_a.m_vData.begin(),tmp_a.m_vData.end(),AddNumber(13));
}
---
But when i try to use them some other way than in combination with STL, I get that:
typedef void (*TraveseFuncPtr) (int&);
void Add7(int& out_Int)
{
out_Int += 7;
}
class AddNumber
{
public:
int m_iToAdd;
AddNumber(int in_iToAdd = 0)
{
m_iToAdd = in_iToAdd;
}
void operator()(int& out_Int)
{
out_Int += m_iToAdd;
}
};
class A
{
public:
std::vector < int > m_vData;
void TraverseVector(TraveseFuncPtr in_func)
{
for (int i = 0; i < m_vData.size(); i++)
{
(*in_func)(m_vData[i]);
}
}
};
void main()
{
A tmp_a;
tmp_a.m_vData.push_back(7);
tmp_a.m_vData.push_back(5);
tmp_a.m_vData.push_back(6);
tmp_a.TraverseVector(Add7); // All ok.
tmp_a.TraverseVector(AddNumber(13)); //C2664
}
---
And thats it.
error C2664: 'TraverseVector' : cannot convert parameter 1 from 'class AddNumber' to 'void (__cdecl *)(int &)'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I tried to dig up STL source but hell the same for_each takes a CLASS (!) as a template parameter.
No functions there.
Who can say anything to this?
Sincerely yours, Ilya Kalujny.
|
|
|
|
|
Yes, but what you have defined as the argument to the TraverseVector is simplay a function pointer:
typedef void (*TraveseFuncPtr) (int&);
Function pionters are not quite the same thing as function objects. If you want to define a function that accepts as a parameter a functor (some class which has an overloaded operator()), then you could make the function a template function and have the exact type of the class you wold pass in a template parameter.
Maybe something like this:
template<class _functortype="">
void TraverseVector(_FunctorType in_func)
{
for (int i = 0; i < m_vData.size(); i++)
{
in_func(m_vData[i]);
}
}
This should allow you to pass in an aribtrary type as an argument, so long as it had an overloaded operator() with the correct signature.
|
|
|
|
|
One question:
Isn't a function object (also named Functor) an object which behaves like a function?.
That means this object has an overloaded operator() returning whatever the object does.
This could be the explanation why the STL wants a CLASS - it calls its operator().
For your Add7-Object it would look about like
class Add7()
{
int operator()(int& out_Int)const
{
return out_Int + 7;
};
} This can be further complicated by making the class Add7 a template.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
One way to do what you want would be to make the traverse vector method a template method. I recommend against doing this, using STL means using all (or as much as you can manage) of it - so you should attempt to reuse tools like for_each wherever you can. for_each works along the same lines as the attached code, but may be optomised by the library for some template specialisations.
The problem, passing extra information to a functor (function object), that you're putting forward is quite common, binders are a good place to look if you're interested in more generic solutions to this problem.
class A <br />
{<br />
public:<br />
std::vector < int > m_vData;<br />
<br />
template<class F><br />
void TraverseVector(F in_func) <br />
{<br />
for (int i = 0; i < m_vData.size(); i++) <br />
{<br />
in_func(m_vData[i]);<br />
cout << m_vData[i] << endl;<br />
}<br />
}<br />
<br />
};
|
|
|
|
|
You are not passing a pointer to a function:
tmp_a.TraverseVector(AddNumber(13));
(passing the return value of AddNumber(13) to TraverseVector(), which is void/nothing/nada).
This is passing a pointer to a function:
tmp_a.TraverseVector(AddNumber);
Trust in the code Luke. Yea right!
|
|
|
|