|
Goh,
Hope this helps...
FILE* bmp = fopen (szFileName,"rb"); // creates a FILE pointer szFileName
is char[] containing the file name that is passed to the operation.
if (!bmp) return false;//if null e.g no file found
BITMAPFILEHEADER BMPFileHeader;//create handles for the file
BITMAPINFOHEADER BMPHeader;
//fread does the actual loading
fread (&BMPFileHeader,sizeof(BITMAPFILEHEADER),1,bmp);
fread (&BMPHeader,sizeof(BITMAPINFOHEADER),1,bmp);
//check for valid headers date etc..
if (BMPFileHeader.bfType != 0x4d42) {fclose (bmp); return false;}
if (BMPHeader.biSize != sizeof(BITMAPINFOHEADER)) {fclose (bmp); return false;}
if (BMPHeader.biPlanes != 1) {fclose (bmp); return false;}
if (BMPHeader.biCompression != BI_RGB) {fclose (bmp); return false;}
unsigned long BitColor = BMPHeader.biBitCount;
so if success bmp contains a pointer to the bitmap file.
Does this help???? or do you need more info, not sure of your experience etc..
Ross W
|
|
|
|
|
I am a beginner trying to understand the codes
so where does the function knoe which file to create a file pointer. Where should the filename be placed
Thank alot
|
|
|
|
|
The key is szFilename, this will be a character array (string)
that will contain the path of the physical file, like "c:\SomeBitmap.bmp" look for the definition of szFilename
before the call below:
bool ResLoad = SrcImage.LoadBMP24Image(szFileName);
It may well of come from a dialog in which case it would have come from a member variable...
The key thing is that you could simply do this:
bool ResLoad = SrcImage.LoadBMP24Image("c:\\SomeBitmap.bmp");
If there is anything else please ask
|
|
|
|
|
Dear rw104,
Can I have your ICQ or msn number as i feel it is slow to ask you in this way.
I still got lots of queries. Can I sent you the file to take a look thx
Hui Beng
Thx
|
|
|
|
|
Hello,
I'm trying the following code in an MFC project, which is causing a compiler error. I hope you can guide me with any error/mistake in my code:
My Code:
...
#include <MyClass.h>
#include <vector>
...
vector<CString> *g_pvecStrings;
...
void g_MyOtherFunction(void);
...
void CMyClass::MyFunction(void)
{
vector<CString> vecStrings;
...
g_pvecStrings = vecStrings;
...
g_MyOtherFunction();
...
vecStrings.clear();
}
void g_MyOtherFunction(void)
{
CString csMyStr;
...
g_pvecStrings->push_back(csMyStr);
...
}
The MSVC++ 6.0 (SP5) compiler error for the statement marked as (1) above:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::vector<class CString,class std::allocator<class CString> >' (or there is no acceptable conversion)
Please reply on this...
Thanks,
Rgds,
Nirav Doshi
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
MFC classes like CString tend to not play nicely with STL components. Pick one or the other, and try not mix them without some kind of adapter.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thanks Andrew for your reply!
Actually, I have my own CWBString class which basically is wrapping string data, which is (obviously) as a "char * ".
I changed that class references with CString for the purpose of the query post for easy explanation.
If as you're saying, I guess I won't be able to use the vector container! ... Is that it?
Thanks,
Rgds,
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
First line you're trying to assign a std::vector<T> to a std::vector<T>*, which obviously fails, and should fail unless something really fishy is at work here.
Second line you're trying to assign a local variable to a global variable by using the address-of operator on the local variable. This will cause the g_pvecStrings variable to point to memory on an unwinded stack after the termination of the void CMyClass::MyFunction(void) method call.
The correct approach would be to do: *g_pvecStrings = vecStrings; presuming g_pvecStrings != 0. An even more correct approach would be an application redesign, but that's probably just the C++ purist in me talking.
Hope that helps.
--
Henrik Stuart (http://www.unprompted.com/hstuart/)
|
|
|
|
|
Thanks Henrik for your reply!
Henrik Stuart wrote:
First line you're trying to assign a std::vector<t> to a std::vector<t>*, which obviously fails, and should fail unless something really fishy is at work here. The correct approach would be to do: *g_pvecStrings = vecStrings; presuming g_pvecStrings != 0.
The *g_pvecStrings = vecStrings; doesn't work too!
Henrik Stuart wrote:
An even more correct approach would be an application redesign, but that's probably just the C++ purist in me talking.
Thanks for this point! My basic purpose is to call a global function which is going to fill the vector with strings. The filled vector is to be used in two of my class member functions. So to pass the data between the class member functions and the global functions I was doing this.
So, I had the global pointer to a vector, which was to point to a vector which will be allocated on the stack within my member function. From within the SAME function I was releasing and making the g_pvecStrings = NULL ;
Please suggest the right way to get this going!
Thanks!
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Nirav Doshi wrote:
Thanks for this point! My basic purpose is to call a global function which is going to fill the vector with strings. The filled vector is to be used in two of my class member functions. So to pass the data between the class member functions and the global functions I was doing this.
The C++ way is to avoid using anything global and use a static member function instead and static class variable.
John
|
|
|
|
|
Oh! Thanks! )... With my confusion to trying to get my work done within my timeline, I delved into some of my old C-style coding!
I guess, this would be the best way to solve my requirement!
Thanks again!
Rgds,
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Making the variable a class static does little to the design. It just changes the namespace. If it was bad code as a global variable, it is still bad code as a class static.
My question is why can't the vector be passed by address or reference to the global functions. Then you avoid the global variables, true or class statics.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
1. Filling the vector through the global or static pointer isn't a good idea. You should pass the vector to the MyOtherFunction by reference.
<br />
void CMyClass::MyOtherFunction(vector<CString>& vec)<br />
{<br />
vec.push_back(...)<br />
}<br />
2. If the compiler generates error on *g_pvecStrings = vecStrings , I think that your class CWBString is the deliquent (because with CString it works ok). The assignment operator in vector causes assignments of each element. Hence, did you declared correctly the copy constructor or assignment operator in CWBString ?
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Thanks Robert for your reply!
Robert A. T. Káldy wrote:
1. Filling the vector through the global or static pointer isn't a good idea. You should pass the vector to the MyOtherFunction by reference.
I have been trying EXACTLY that now, but it is cribbing about xutility :
c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const class CWBString' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\vector(170) : see reference to function template instantiation 'void __cdecl std::fill(class CWBString *,class CWBString *,const class CWBString &)' being compiled
Robert A. T. Káldy wrote:
2. If the compiler generates error on *g_pvecStrings = vecStrings, I think that your class CWBString is the deliquent (because with CString it works ok). The assignment operator in vector causes assignments of each element. Hence, did you declared correctly the copy constructor or assignment operator in CWBString?
I am using CWBString extensively in my whole project and it has a (deep) copy constructor, as well as almost ALL the operators overloaded for standards as well as varied purposes (varied like *= for IsSimilar() in which I check for similar strings).
So I suppose my problem was that I was trying to use STL containers like normal pointers which can be shallow copied! I hope I'm correct here...
Thanks again!
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Tim Smith wrote:
Making the variable a class static does little to the design. It just changes the namespace. If it was bad code as a global variable, it is still bad code as a class static.
I disagree. There are legitimate reasons to have class static variables and they are definitly not as bad as globals as you can make them private or protected. If the same data will be shared for all instances of an object it makes no sense to store a pointer to the data in each instance.
John
|
|
|
|
|
Hi guys,
is there any possibility to load a jpg or bmp with more than 256 colors in a dialog? i know how it works with a bmp witch has 256 colors.
Thanks in advance!
J.J.
|
|
|
|
|
the problem in this code is that it can't compile it when "A" is defined as "int"
"C:\Documents and Settings\simon\Desktop\the program.cpp(34) : error C2443: operand size conflict"
in my program A is in the range of 1-512 in decimal so thier is no problem with the size.
so how i force it to compile?
or how i change the program to compile it?
void light_port_b(int A)
{
_asm
{
mov Dx,PORTB
Mov Al,A
Out Dx,Al
}
}
thanks in advance
|
|
|
|
|
Register EAX = 4 bytes.
Register AX = 2 bytes.
Register AL = 1 byte.
void light_port_b(int A)
{
unsigned char t = (unsigned char) A;
// sizeof (int) = 4 (bytes).
// sizeof (unsigned char) = 1 (byte).
_asm
{
MOV DX, PORTB
MOV AL, t
OUT DX, AL
}
}
<b>Maxwell Chen</b>
|
|
|
|
|
thanks alot for the quick respond.
i have more questions (sorry if you think that they stupid).
1.as much as i know unsigned char is in the range of 0-255
so if i give him 256-512 it would work?
2. char is defined as a sign and i need numbers so when i write
"MOV AL, t" and int A=256 it moves the number 256 to or the sign of 256 to AL? (i need the number)
|
|
|
|
|
1) For such an expression:
unsigned char t = 257;
t is truncated. Thus, value of t will be 1 as a result.
2) I would suggest you try ...
unsigned short bbb = A;
_asm
{
MOV DX, PORTB
MOV AX, bbb
OUT DX, AX
}
<b>Maxwell Chen</b>
|
|
|
|
|
sorry it's in the range of 1-256
so if i will write "unsigned char t = (unsigned char) A;"
between 1-255 AL will get the same numbers.
and if i will give A,
the value 256, AL will get the number 0,and i would know it was 256.
I understood you correctly?
|
|
|
|
|
My only comment is unless you are in a device driver the Out Dx,Al will probably throw a hardware exception in NT, 2K, 2K3 or XP.
John
|
|
|
|
|
not only probably... it will!
Don't try it, just do it!
|
|
|
|
|
That's what I thought but I have ran some old dos games (in XP) with soundblaster and they worked. I was surprized of this. Do you know how this works?? Is it because of the VDM?
John
|
|
|
|
|
I create a signed message with CryptSignMessage, but I found this function would read the whole data to be signed into memory, if I want to sign a file which size is 100MB, I must malloc 100MB memory for it.
I need a solution that can sign message as a block by block.
|
|
|
|