|
Hello,
I am trying to load up bitmaps onto DirectX surfaces. Well anyway...
this is the function prototype:
Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
so I tried to read the bitmap names from a file with the following:
<br />
infile.open("TileBitmap.dat");<br />
int value = 0;<br />
char tempFilename[256] = {0};<br />
<br />
<br />
while(infile)<br />
{<br />
infile >> value;
infile.getline(tempFilename, 256);
MessageBox(main_window_handle, tempFilename, "Test", MB_OK);<br />
<br />
if (!(Load_Bitmap_File(&bit, tempFilename)))<br />
{<br />
infile.close();
return 0;
}<br />
LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT);
<br />
}<br />
infile.close();<br />
and the darn thing fails with the Load_Bitmap_File
notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap.
So I tried... manual initialization
<br />
char tempFilename[256] = "filename.bmp"<br />
Load_Bitmap_File(&bit, tempFilename);<br />
and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks!
-Pizzaman
-It's like blowing up an abortion center because you are pro life.
|
|
|
|
|
Is it possible that tempFilename contains an embedded LF or CRLF at the end of the string? That would explain why it would display fine in the message box, but would still bomb out. Stepping through in a debugger would be advised
- Mike
|
|
|
|
|
Yes, that is most likely the case, because the file is setup as...
0 grass1.bmp
1 grass2.bmp
2 grass3.bmp
.
.
.
-Pizzaman
-It's like blowing up an abortion center because you are pro life.
|
|
|
|
|
When using infile.getline(tempFilename, 256); , could there be extra (hidden) characters in tempFilename ? MessageBox() is not exactly the best choice to use for looking at data.
Using both methods you described, put a breakpint on the Load_Bitmap_File() line and look at tempFilename in the debugger at that point. See if there are any differences between the two.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I've been handling with a soccer game using STL and have the following function..
set<game>::iterator gameIterator = tournament->sche->games.begin();
Game *currentGame = new Game();
*currentGame = *gameIterator;
Then i have a function:
startGame(currentGame);
however, after the fuction, the currentGame's properties are updated. but not the properties for that particular game in
tournament->sche->games
Can anyone tell me why?
Thanks..
Jass
|
|
|
|
|
*currentGame = *gameIterator; This makes a copy of the object pointed to by gameIterator . Any changes you then make to currentGame are not reflected in your set tournament->sche->games .
I would suggest
set<Game>::iterator currentGame =
tournament->sche->games.begin();
startGame( currentGame ); and change the declaration and implementation of startGame to take a set<Game>::iterator instead. You'll then be working directly with your container.
You might need to check the definition of set<> 's member functions to check that it won't produce copies.
By the way, is there some reason you need an ordered unique container of Game objects? I would normally recommend using a list<> , vector<> or deque<> for an arbitrary collection.
Use list if you need to insert or delete from the middle of the list, and you don't need to access elements by index very often. Use vector if you need to be compatible with C arrays, index a lot, don't add or delete in the middle of the container or at the beginning, and rarely add new elements to the end. Use deque if you need to access by index but still need to add or delete in the middle of the container.
|
|
|
|
|
set::iterator gameIterator = tournament->sche->games.begin();
1. gameIterator now points to the tournament->sche->games.begin()
Game *currentGame = new Game();
2. currentGame now points to a new Game
*currentGame = *gameIterator
3. You new Game now has same data as the tournament->sche->games.begin(); because of member-wise assignment.
startGame(currentGame);
4. You passed in pinter to new Game made in step 2. you DID NOT pass in any reference to the original tournament->sche->games.begin()
Result : you modified the contents of the new Game filed and nothing to do with the contents or values of the iterator.
A much simpler example:
int * px = new int;
int * py = new int;
*py = *px <- y now has value of x
SomeFunction(py);
is only going to modify the value of y, x will remain entirely unaffected.
The memories of a man in his old age are the deeds of a man in his prime.
|
|
|
|
|
Hi all...
How can I Receive Remote machine Information????
|
|
|
|
|
Well that would depend what kind of information you are looking for now wouldn't it? The canonical answer is probably WMI.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Dear all,
I am developing an application using MFC VC++ Version 6.0 for Windows 2000.
I need to capture login and log off event in my application. Is there any event (or API) to capture these events
Thanks
rohit
|
|
|
|
|
If your application is an ordinary application, it will be terminated when the user logs off, because Windows tears down the session.
Windows sends a WM_QUERYENDSESSION message, followed by a WM_ENDSESSION message, when the user logs off or shuts down the system. See the documentation for the exact semantics.
If you're trying to handle user switches on Windows XP, see the KB article HOW TO: Write an Application That Supports Fast User Switching in Windows XP[^].
(edited for formatting)
|
|
|
|
|
Thanks mike you solved my purpose
|
|
|
|
|
Can somebody help me with getting my pointer declared correctly so I can access the unsigned int x in 2 byte pieces? The book I have is very vague on how I am supposed to go about. Not much for example code. But I think I am close.
Here ya go:
<pre>typedef struct
{
unsigned short int x;
} myStruct;
void main()
{
char c;
myStruct s;
s.x = 1;
((char *) &s.x)[0]; //subscript to read first byte
printf("%d\n",&s.x);
} </pre>
|
|
|
|
|
I think your question was answered elsewhere, but it might be helpful to know about union structures to accomplish something like this.
Example:
union PeekInt {
unsigned short int i;
struct {
char b1;
char b2;
} bytes;
} mpi; This specifies that the mpi.bytes structure occupies the same memory space as mpi.i , so mpi.bytes.b1 will let you access the first byte and mpi.bytes.b2 will let you access the second byte.
- Mike
|
|
|
|
|
Yes, thank you for that example. Thats what my book(Daniel W. Lewis, "Fundamentals of Embedded Software") needs to focus on, putting more examples in it. It don't really show you much examples or how to's, it just assumes everything is bread and butter to you. Very frustrating. With your example and a few other tips I got from this forum, I am going to be ready for the test tomorrow.
Thank you.
Brian.
|
|
|
|
|
Hi I have MS Visual C++ 1.32, is there any possible way I can upgrade to something newer without paying the cost of 6.0 itself. I mean, is there a free way to upgrade to 4.0 or 5.0 or even 6 without buying the full 6.0 version.
I may sound cheap, but I'm in a college class for C++ and It would really help me if I had a newer version. 1.32 doesn't work with all the code that 6.0 does.
Well if there is anyway to upgrade I would really appreaciate the help!
Sincerely
Matt
|
|
|
|
|
It's amazing that you have version 1.32! The oldest version I have is 1.52c. You can pick up version 6.0 Professional for about $50 at this EBay auction[^] if you hurry. Good luck!
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
For a definitive answer, check out this Web site! It looks like the oldest version they'll let you upgrade from is 5.
These may also be of interest to you:
http://www.msdnaa.net/factspage.aspx
http://www.microsoft.com/education/?ID=HowToBuy
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
|
Can somebody tell me what I am doing wrong what the correct syntax is for formatting your output in binary representation.
I have been using printf("%b\n",variable) like the the help files says in .NET but it just keeps outputing a b on the console.
And does anyone know the correct syntax in C for packing your structures?
Help.
Thanks.
|
|
|
|
|
I think you have been looking at the wrong printf format specification.
There is no format that outputs binary in C (neither std or ms extension).
There is no specific packing or alignment keywords in C.
Use the pack pragma and the align declspec.
|
|
|
|
|
Okay, I found something about that pragma but Im not sure how it works with packing the data. Hmmm. Got any ideas.
I found: pragma pack(push, 1) or something like that. Not sure what it does though.
Does C++ have binary formatting?
|
|
|
|
|
About formating, nope. Actually it is printf that lacks it and it's the same for both languages.
Concerning packing, what are you trying to accomplish? Kind of hard to try to help without more info...
|
|
|
|
|
What I'm trying to do is write a struct in C with a couple data types in it, i.e. int, char.
<pre>typedef struct
{
int x;
char c;
}_attribute_((packed))myStruct</pre>
This syntax is for djgpp compiler, I was wondering what you use for .NET or Visual C 6.
|
|
|
|
|
#pragma pack(push, 1)
What this does is set the struct packing to 1-byte boundaries (i.e., no padding), while saving the previous packing. Specify this before your struct, then use #pragma pack(pop) after the struct to restore the old packing. Example:
<br />
#pragma pack(push,1)<br />
struct MyStruct {<br />
int foo;<br />
char a;<br />
};<br />
#pragma pack(pop)<br />
- Mike
|
|
|
|