Hey,
I am affriad to say MFC 8 that comes with VS 2005 isnt stable at all. im working in a studio trying to work on a project, and i keep on wasting time on worthless issues.
All of which have to do with pointers and the new operator.
Latest issue is it will declare thepointer if i told it to load configuration from a file. but it wont declare it if i decide to load the configuration manually, i really dont know what difference does it make. im using the exact same code for declaring a pointer, and it refuses and gives me the following message:
http://img85.imageshack.us/my.php image=error7qz.jpg followed by Out Of Memory, also i dont know why. in that message, the path on H directory is valid. but the directory on drive F as it has on message box isnt valid at all, i have all folders shown, nothing hid.
another issue, in a std::vector object. i declare it as std::vector<char*>* myVector.
it accepts char array[260]; in the push_back() but it wont accept char *array; in there. it throughts out of memory exception. and when i give it the char array[260] object, the function returns a pointer to a struct with all of the std::vectors i have. the content of all char* type vectors are corrupted, why is that
one last question, why are there 100 different tpe of strings in C++ bstr, char*, wchat_t, tchar. i understand each one has its own purpose for existance, but why do u force some api's to use one kind of strings, for example in the msxml dll, when i import it for use, i have to convert my char's to wchar_t then to bstrs, to put something in xml, and vise versa to read something out of xml file.
i am using VS2005. and this is MFC application.

VC++/MFC 8 not stable
Gary Short
how could i traverse data of the vector if its vector<string>
i tried it but iut wont work.
Jim Walkling
Could you show some code That'd help identify what the errors are due to.
As for different string types, it's nothing to do with MFC really. BSTRs are there for COM, std::string is part of STL, char* and wchar_t* are part of the C/C++ language, TCHAR is a conditional typedef that's there for convenience etc. CString is the string type introduced by MFC - and is probably a far better string class compared to STL string or using C style character pointers.
big9s
i manged to solve the problem for this pointer declaration thing. it was in the mfc application when i get the array from CString from open dialog box.
i copied the char's out of CString wrong. i didnt copy out the NULL Terminator apparently strcpy doesnt do that automatically.
that solved my problem there.
and i also tried doing an array of strings by char* array[260]; and that worked as opposed to my old declaration char** array;
thx
signal5
oh and i tested out something very weird. if i added a messagebox in the initialization part of the dialog. the application displays the message box and runs normal :s but yet again it crashes in some code which is perfectly right.
so i guess there is some pointer(s) problem in there in my code.
Theodore Chen
PhilMatt
well NMaterial i inherit from the D3DMaterial9 structure as follows:
typedef
struct NMaterial: public D3DMATERIAL9{
public:NMaterial()
{}
}
thats the struct from NMaterial.
and the struct for D3DMaterial9 in direct3d is as follows:
typedef
struct _D3DMATERIAL9 {D3DCOLORVALUE Diffuse;
/* Diffuse color RGBA */D3DCOLORVALUE Ambient;
/* Ambient color RGB */D3DCOLORVALUE Specular;
/* Specular 'shininess' */D3DCOLORVALUE Emissive;
/* Emissive color RGB */ float Power; /* Sharpness if specular highlight */} D3DMATERIAL9;
is there something wrong in what i did
Aders
Perhaps there's an issue in the NMaterial constructor. What does the call stack say
rasky74
To track down your crashing bug, run it outside of VS, let it crash, and use the Debug button on the subsequent dialog. It will then let VS attach to the process so that you can see where the bug really is.
Brian
t_o_n_y
NMaterial* m_pMaterial = new NMaterial[m_dwNumOfMaterials];
this sometimes works and somethings doesnt. on same mesh object.
notice the "m_dwNumOfMaterials" varioable always has a value of atleast 1.
maestro_h
As moderator, I changed the subject line of this thread to more accurately describe what this thread is about for the benefit of other readers.
In response to your last post, it would behoove you to understand exactly what you're doing when it comes to char*[]. We can help with that, because understanding the complexities of C++ is something we've been through. Making a problem go away is different than "solving a problem." There's a good chance that you haven't made your problems go away after all, because as evidenced in your other thread (running outside of VS), one of your attempted fixes didn't really work.
Oh, and one more thing. strcpy does copy over the null terminator of the source string. Always, without exception. strcpy starts with the first character (you give it the pointer), and keeps on copying until it encounters a null terminator, and copies that also.
Brian
raewear
If your char[] array is a local variable and the std::vector is not (e.g. part of a class allocated elsewhere), then pushing it into a vector is the wrong thing to do because by doing so, you're placing a pointer to a local variable that goes out of scope.
Unless you have an adversion to making copies of strings for performance reasons, you ought to just use vector<string> to maintain an array of strings. by using char*, you're taking on the dynamic allocation and deallocation responsibilies. Vectors of instances (as opposed to vector of pointers to instances) are easier to work with because then the construction and destruction of those instances are done by vector.
e.g. Wrong:
void foo( vector<char*>& myvec )
{
char mystring[100]="mad dog";
myvec.push_back( mystring ); // pushes the pointer to "mad dog" on stack, which is later "garbage" because the pointer is pointing into this stack frame!
}
Right:
void foo( vector<string>& myvec )
{
char mystring[100]="mad dog";
myvec.push_back( mystring ); // creates a temporary string object, copies contents of mystring into it, and pushes it onto the stack (via copy constructor to an instance owned by vector)
}
I think the compiler can optimize out the temporary string creation, btw.
Another way, but not recommended:
void foo( vector<char*>& myvec )
{
char mystring[100]="mad dog";
myvec.push_back( strdup( mystring ) ); // creates a copy of mystring on the heap, but you better be sure to iterate myvec later and call free() on each element!
}
HarryX
I would recommend focusing on using a debugger to diagnose the problem.
Also, you can set a hard-coded breakpoint in your application using __debugbreak().
Brian
rajitha
i guess C++ is too powerful that its powerness can easily cause critical problems if miss used :S
Macius
You previously asked:
how could i traverse data of the vector if its vector<string>
It's not clear what you're asking. Are you asking how you iterate each character of the string, or are you asking how to iterate each string of the vector
Brian