VC++ project hangs at startup?
-
29 сентября 2005 г. 22:43Hi,
I was wondering if anyone has the same problem as I do. Currently my project hangs when I startup VC++. I can not figure what is wrong with my project. I can not even open my project at all.
I did not do anything different when creating the project. I started off by creating an empty new project, added 1 windows form, and couple source/file files which I added and wrote myself. I was wondering can open my project to see if they have the same problem also. I tried opening my project on other computers at my work, and it worked, but once I open it again it hangs?
Anyone willing to help me out? Thanks!
Все ответы
-
30 сентября 2005 г. 15:06
I've experienced the same problem, the project just hang's on loading and you have to shutdown VS. If you haven't, try putting all your declarations underneath the form's initialisation method, it's been working for me so far but I doubt if this is the answer.
I've also noticed that this type of crash happens when I've coded function templates, particularly when specialising. I'd cut and paste the function declaration I want to specialise then adjust the parameters to suit, but once I paste and this multiple definition happens it freezes on me, I have to put comments in, paste into them, do the adjustment and uncomment.
-
30 сентября 2005 г. 16:29Hi,
Thanks for the insite. So your suggesting in the form's header file, move all the #defines, includes, using namespaces, etc. below the declaration of the form class?
So for instance in form.h:
class form:System::windows::forms::form
{
form1(void)
{
initializecomponent();
}
//put declarations of variables/functions here
}
All my function declarations are below the intialize component, but my public variable declarations are on top of that.
Also, what do you mean by specialising when coding function templates?
Thanks for the reponse! -
1 октября 2005 г. 4:04
That's what I think the problem might be, the data types being mixed with the resource stuff.
public __gc class Form1 : public Form
{
public:
Form1(void)
{
InitializeComponent();
// Initialise user types, no problem
}protected
:
void Dispose(Boolean disposing)
{
// Dispose user types, no problem
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}// This bit is for resources,
private: System::Windows::Forms::MainMenu * mainMenu1;
// I think this should be left alone,
// VS likes to put its own things here
private: System::Windows::Forms::ToolBar * toolBar1;
private: System::Windows::Forms::MenuItem * fileMenuItem;// ...
private
:
System::ComponentModel::Container * components;
void InitializeComponent(void) {}// Put my declarations here,
viGraphics* m_Graphics;
// away from the resource declarations and initialisation
bool
CreateDevice(){}//...
};First I thought the problem was happening because I was mixing managed and unmanaged code, it still might be, but when the unmanaged project with the template functions exhibited the same thing I started thinking if it's the way the editor loads and presents the information. So as a test I thought I'd keep all my code as far away as possible from the resource stuff that VS uses and so far things have been good. If it'll last I don't know, I feel VS might be toying with me till a critical moment when it'll strike.
Specialisation is like overloading:
// A simple function to test if 'a' is greater than 'b'
template<class T> bool IsGreaterThan(const T& a, const T& b)
{
return (a > b);
}// Specialised version for character strings
template<> bool IsGreaterThan(const char& a, const char& b)
// notice the <> signifying a specialisation
// notice that 'char' now represents 'T'
// notice the rest of the declaration is the same as the
// function that's being specialised
{
return (strcmp(&a, &b) > 0);
}You have to be careful with templates. If you had two character strings, s1 and s2, you could compare them like this:
IsGreaterThan(*s1, *s2)
But the same function would be called if you were comparing two characters:
IsGreaterThan('a', 'b')
You might not want strcmp() for this type of comparison.
// general template
You can also specialise template classes:
// used for array of objects of type T
template<class T> class MyArray
{
T* ptr;
size_t sz;public
:
MyArray(size_t arr_sz): sz(arr_sz) { ptr = new T[sz]; }
~MyArray() { delete [] ptr; }
T& operator[] (size_t idx) { return ptr[idx]; }
size_t array_size() const { return sz; }
}; // specialisation
// used for array of void* only
// notice that T is now represented by void*
template<> class MyArray<void*>
{
void** ptr;
size_t sz;public
:MyArray(size_t arr_sz): sz(arr_sz) { ptr =
new void*[sz]; }
~MyArray() { delete [] ptr; } void*& operator[] (size_t idx) { return ptr[idx]; }
size_t array_size() const { return sz; }
}; // partial specialisation
// used for array of any pointer type except void*
// this class is basically a wrapper to cast void* to T*
// notice the static_casts<>() and the use of the base class
template<class T> class MyArray<T*> : private MyArray<void*>
{
public:
MyArray(size_t arr_sz): MyArray<void*>(arr_sz) {}T*&
operator[] (size_t idx)
{
return static_cast<T*&>(MyArray<void*>::operator[](idx));
}size_t array_size()
const { return MyArray<void*>::array_size(); }
};
You would then declare like:
MyArray<int> iarr(5); // MyArray<T>
MyArray<void*> pvarr(5); // MyArray<void*>
MyArray<int*> piarr(5); // MyArray<T*> -
21 февраля 2006 г. 12:28
I start VC 6.0 and open a project: Statusbar says it loads ..... after the bar is filled, the project workspace is empty and it seems as I havn't loaded anything.
This happens every few months, after some days I can open the project normally but I don't know why???
I ran checkdisk and found errors on the drive on which VC is installed, but no errors on the drive on which the project files are stored.
Does anybody know why I cannot open my project?
Yesterday another 'interesting' thing happend: I startet a new project, because my old one cannot be opened. I tried to add files to my project and VS crashed (Exeption ....).
Please help.
Chris

