|
Hey Gentlemen, I contemplated opening a new thread for this question, but hopefully this one will do.
I think I understand what is going on with the darn pointers and interators and how I used them. Unfortunately I'll need to rewrite a lot of things.
However, I'm having another problem with another compiler error.
c:\nehe\magi\magination\spelllist.cpp(1275) : error C2228: left of '.current_energy' must have class/struct/union
The code is question is
caster.Creatures[i].current_energy = nrg[i];
I'm not sure what this "must have class/struct/union means.
Any help would be much appreciated.
|
|
|
|
|
This is typically the cause of that error (at least for me):
CMyObject* pObj = new CMyObject();
pObj.DoSomething();
Try changing it to:
caster.Creatures[i]->current_energy = nrg[i];
and see if that works.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Is there any fuction that compare 2 strs
str1 = "BMW"
str2 = "BmW"
and that fuction would return TRUE (or something else) while comparing these 2 strs?
or should i create that fuction ?
|
|
|
|
|
What are str1 and str2 ? char arrays ? std::strings ? CStrings ? bstr_t ?
Most string classes offer operator ==. Two char * can be compared with strcmp, from memory.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
I just want to return me true below :
CString str = "BMW";
CString str2 = "BmW";
CString str3 = "bMW";
if ( str == str2 && str2 ==str3) etc
|
|
|
|
|
use CompareNoCase function of CString..
|
|
|
|
|
Well i am facking idiot :/ it was inside my eyes and i did a whole post :/
|
|
|
|
|
hm i found MakeUpper for CStrings
so i will make them MakeUpper before i put them in if ( ) {}
right?
|
|
|
|
|
if (0 == str1.CompareNoCase(str2))
{
//strings are equal, ignoring case
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
thx about that too (i will use this and not that i said about MakeUpper)
|
|
|
|
|
The old-skool strxxx functions have versions that ignore case - e.g. stricmp()
The i is for ignore!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi all. Im trying to find a reasonable explanation on how to call the ExitThread() function properly. Would i need to call it for every thread i call?
ie:
<br />
<br />
CreateThread(somethread);<br />
CreateThread(somethread);<br />
WaitForMultipleObjects(somethread);<br />
<br />
ExitThread(somethread);
Thanx in advance!
|
|
|
|
|
dellthinker wrote: Would i need to call it for every thread i call?
No. your thread will automatically end when you return from the thread function.
|
|
|
|
|
ExitThread exits the current thread, not some arbitrary thread identified by a HANDLE . The argument is an exit code not a HANDLE .
Steve
|
|
|
|
|
Hello everybody,
lets say i have small 640bytes executable with a code like this:
#include "windows.h"<br />
<br />
int WinMainCRTStartup()<br />
{<br />
MessageBox(0,"AAA","BBB",0<br />
return 0;<br />
}
.rdata and .text sections are merged so there is only one .text section in that *.exe
so what i need to do to add new section manualy, with hexeditor?
i know that i have to add new Image Section header which is 28 bytes lenght and new section at the end of file which is random lenght described in its section header.
I also have to correct each section pointer(in my case just one section) so if i add additional 28 bytes in front of sections i have to add 28byte to each section pointer so in my case offset will be 200+28, but my hexeditor shows that ofset to the section begining is 208, so i will better trust my hexeditor. And finaly i changed sections count to 2 so.. chages were made executable saved but it doesn't work.
what i have missed?
thank you for help in advance
|
|
|
|
|
This should get you started:
#include "stdafx.h"
#pragma data_seg(".MySeg")
int g_ImInAnotherSegment = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.MySeg,RW")// Make section readable and writable.
int main(int argc, char* argv[])
{
return 0;
}
Steve
|
|
|
|
|
my application currently reads and uses data from files at a location on the host machine using fstream
what i would like to do is include these files and their data as resources so that the application does not rely on the data being stored on the host machine
i am using FindResource, LoadResource, LockResource etc but i'm having trouble passing the actual data content straight to fstream - is this possible??
<br />
FindResource(..);<br />
LoadResource(..);<br />
char* ptr = (char*) LockResource(..);<br />
<br />
fstream.open(ptr,ofstream::binary);<br />
any help would be greatly appreciated - i'm pretty new to resources!
|
|
|
|
|
bimgot wrote: char* ptr = (char*) LockResource(..);
What do you want to do with ptr at this point?
bimgot wrote: fstream.open(ptr,ofstream::binary);
The first argument to fstream 's constructor is the name of the file to open, not the actual data within the file. Perhaps that is where your confusion lies.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
as i understand LockResource returns a pointer to the first byte of the data stored in the resource.. currently i use fstream to read, validate and store some wave file data so that it can be used to play back the wave file
since the open function of fstream takes a char* for the name of the file to open, i wondered if a char* for the resource would work in the same way
i think my confusion is as you say with fstream but since the class i want to use the data from the resource with is based on fstream, i wondered if there was a solution that doesnt involve re-writing the class..
|
|
|
|
|
I was wondering how the operating system handles this (if it's at all possible). I was thinking that the main thread could hook itself to an event (that when signaled, outputs the word "foo" to console) and then spawn a child thread that does some work. When the child thread is done work, it would raise a signal to the event that the main thread would catch, before the child thread terminates.
The concept I'm having trouble working around is the following:
Main Thread Child Thread
|
|--------------------------->
| |
| |
| |
|<---------------------------
|
|
When the child thread raises the signal, and the main thread catches it, would it stop whatever it's currently executing to write the word "foo" to console, then continue on with whatever it's doing?
|
|
|
|
|
Sure, if you posted the data back to the main thread through for instance a user-defined windows message.
I do this sort of thing a lot in for instance socket programming, like pressing the "Connect" button of a chat program. Without having a separate thread, the whole program could freeze up for several seconds as the socket attempted to connect, since it's a blocking call.
KR
|
|
|
|
|
The main thread would have to be waiting on a synchronisation object, a message queue or event in order to respond to the child threads signal. You can't preemptively interrupt any thread except to suspend it, resume it or terminate it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Well, I was thinking of using this method to hook the main thread to the event:
Native C++ Event Handling
However, hooking to an event doesn't imply that your main thread can no longer do anything but wait for the event, which led to my above question.
|
|
|
|
|
I don't know if this would work. I suspect the event function would get called on the child thread or a temporary thread rather than on the main thread.
Although Microsoft labels all this up as 'Native' you'll notice the bracketed [event_source(native)] attributes indicating managed extensions. I guess this probably works like the COM event system where the child thread will get temporarily suspended when it raises the event and then the rutime will actually scrape up (probably from a pool ) a separate system thread to call the event handler on, releasing the child thread to go its merry way after the hand off of any parameters. You could do this in straight C++ but being able to hand off any set of parameters is, I suspect, what's going to require the compiler magic indicated by [event_source(native)]. It's going to have to write some code for you based on the definition of the event class
Personally I would use a straight forward Event object and have the main thread poll (WaitForSingleObject with a short timeout) for it periodically.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|