|
Hi,
1.
as long as there are compiler errors, you are not running your new code.
you are either running a previous version (the last EXE that got build successfully), or not at all.
which it is depends on some option (see menu Tools/Options/Projects and Solutions/Build and Run/On Run, when errors occur...; I suggest "Do not launch").
2.
this->label1->Text=DateTime::Now.ToString("T");
works fine for me.
|
|
|
|
|
Okay, so this is what I tried just now...
1. Make a brand new Windows Forms Application project (in Visual Studio 2008 Professional Edition).
2. Place a Label control on the empty form.
3. Select View | Code.
4. Change the line that reads "this->label1->Text = L"label1";" to "this->label1->Text = DateTime::Now.ToString("T");"
5. Select Build | Build Solution.
6. The code editor says the build succeeded.
7. I click the "Form1.h" tab to switch to the design editor, and it says "C++ CodeDOM parser error:Line:70,Column:47 --- Internal Error".
So am I doing something wrong, or missing something?
|
|
|
|
|
Your code is correct, but you should not modify "by hand" the code inside the InitializeComponent method. You should put your custom initialization code inside the constructor, after the call to InitializeComponent() .
|
|
|
|
|
Wohoo! That did it. Thanks!
|
|
|
|
|
Hello, I need to know how to chagne text color.
for example, I declar a text variable
System::Object^ text; how do I change the color of variable text.
thanks.
|
|
|
|
|
i think you should get a book or start from http://msdn.microsoft.com/en-us/library/w0x726c2.aspx[^]
because you are missing the basics
...anyway in one form you can add this code:
System::Windows::Forms::Label ^my_label=gcnew System::Windows::Forms::Label();
my_label->ForeColor=System::Drawing::Color::FromArgb(255,0,0);
my_label->Location = System::Drawing::Point(0, 0);
my_label->Text = "my personal text";
and then add the object to some control object like form's one
this->Controls->Add(this->my_label);
|
|
|
|
|
jashimu wrote: System::Object^ text; how do I change the color of variable text.
You don't. A System::Object does not have a colour attribute, and if it did it would still not be much use. Text formatting is applied when the text is displayed on an output device such as a screen or printer. I also wonder why you are declaring a text item as a System::Object , I'm sure there is a more appropriate class to use.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Sorry, wrong Forum, please delete this Thread
Hallo,
I upgraded from Visual Studio 2005 to Visual Studio 2008, and converted my Project from from VS2005 to VS2008.
But now I get an Error in the following lines:
LOGFONT lFont;
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
lFont = ncm.lfMessageFont;
SystemParametersInfo() returns false, and there are the following Values in ncm after executing the SystemParametersInfo() Function:
When I open my Project in Windows 7, it works without problem. In XP I get an access exeption in msvcr90d.dll when I ignore the failed execution of SystemParametersInfo.
Can someone help me?
Thank you!
|
|
|
|
|
Are you generating a manifest file?
|
|
|
|
|
Hello,
I'm using VC++.I have a TextBox, and want to convert its String^ value to a char[512] array ???
I thank CodeProject...
|
|
|
|
|
use the search function of the forum....this has been discussed so much times...
hint: look for System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi then it'll be easy
|
|
|
|
|
Use MSDN[^] for simple questions; you even get the title: How to convert from System::String* to Char* in Visual C++. I'm sure you can work out the extra steps needed for yourself. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Basically i have 2 class (extended_1_GrObject and extended_2_GrObject) that derive from a general abstract class(basicGrObject):
public ref class basicGrObject abstract
{
public:
basicGrObject(){}
virtual void calculate() abstract;
protected:
~basicGrObject(){}
};
public ref class extended_1_GrObject : public basicGrObject
{
public:
extended_1_GrObject()
{
}
virtual void calculate() override
{
}
protected:
~extended_1_GrObject()
{
}
};
public ref class extended_2_GrObject : public basicGrObject
{
public:
extended_2_GrObject()
{
}
virtual void calculate() override
{
}
protected:
~extended_2_GrObject()
{
}
};
In my code i create a list of this object and foreach element i have to call the calculate method
System::Collections::ArrayList ^my_list=gcnew System::Collections::ArrayList();
extended_1_GrObject ^extended_cl_1=gcnew extended_1_GrObject();
my_list->Add(extended_cl_1);
extended_2_GrObject ^extended_cl_2=gcnew extended_2_GrObject();
my_list->Add(extended_cl_2);
for (int i=0;i<my_list->Count;i++) {
if (my_list[i]->GetType()->Name=="extended_1_GrObject" ) {
extended_1_GrObject ^tmp=static_cast<extended_1_GrObject^>(my_list[i]);
tmp->calculate();
}
else if (my_list[i]->GetType()->Name=="extended_2_GrObject" ) {
extended_2_GrObject ^tmp=static_cast<extended_2_GrObject^>(my_list[i]);
tmp->calculate();
}
}
i really don't like to do the ' my_list[i]->GetType()->Name=="extended_1_GrObject" '
is there some way to avoid that problem, my real class have list of 10000 elements and 10000 string comparison are very very heavymodified on Thursday, March 18, 2010 7:29 AM
|
|
|
|
|
This should work for you (note: psuedo code).
extended_1_GrObject ^extended_cl_1=gcnew extended_1_GrObject();
my_list->Add(extended_cl_1);
extended_2_GrObject ^extended_cl_2=gcnew extended_2_GrObject();
my_list->Add(extended_cl_2);
for (int i=0;i<my_list->Count;i++) {
basicGrObject ^tmp = static_cast<basicGrObject^>(my_list[i]);
tmp->calculate();
} Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Sometimes looking for something simple is the best way...thank you
|
|
|
|
|
Hi,
I want to convert CString array to managed code ot send it to C#.
For normal CString i did like this,
CString menu = "MENU";
String ^ msg = gcnew String(menu);
Globals1::gwtoolbar->Add(msg);
But now i want to send array of string.i dont know how to do for CString array.
When i gave like this it shows error
CString menu[10];
String[] ^ msg = gcnew String(menu);
How can i convert it?Anu
|
|
|
|
|
I think you need to use the managed array ; see the documentation here[^] for some samples.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You would have to do something like this:
array<String^>^ managedArray = gcnew array<String^>(5);
CString nativeArray[5];
for (int i = 0; i < 5; i++)
{
managedArray[i] = Convert::ToString(i);
nativeArray[i] = gcnew String(nativeArray[i]);
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
gcnew System::String(char *)
|
|
|
|
|
Try this once
CString menu[5];
menu[5]={"1","2","3","4","5"};
String[] ^ msg = gcnew String(menu);
msg += " (System::String)";
|
|
|
|
|
hi, i have a problem when calling from the managed code the function
capGetDriverDescription(
WORD wDriverIndex,
LPTSTR lpszName,
INT cbName,
LPTSTR lpszVer,
INT cbVer
);
from avicap32.dll. the function is described in detail in http://msdn.microsoft.com/en-us/library/dd756909%28VS.85%29.aspx[^]. Basically it writes the name and description of videoinput device number wDriverIndex to the passed strings lpszName and lpszVer which have length cbName and cbVer respectively (better put, to the corresponding memory). the relevant code is the following
-----------------------------------------
[DllImport("avicap32.dll")] extern "C" bool capGetDriverDescription(UInt16, String^, int, String^, int);
.....
int i_nameLen = 100;
int i_verLen = 100;
String^ s_name = gcnew String('x',i_verLen);
String^ s_ver = gcnew String('x',i_verLen);
result = capGetDriverDescription(x, s_name, i_nameLen, s_ver, i_verLen);
------------------------------------------
the function returns for x=0 true and for x=1 false which is expected since only one webcam is attached to my computer. but the returned strings s_name and s_ver are unchanged. probably managed and unmanaged code dont use the same memory which makes it somewhat difficult to pass pointers.... what is the alternative?
btw, its my first time calling unmanaged code from managed one, so probably the answer will be quite obvious. thanks in advance!
david
ps: is there a smarter way to allocate memory to the strings? (probably yes...)
|
|
|
|
|
To use a string as an output parameter you should use the StringBuilder class instead of String .
[DllImport("avicap32.dll"),CharSet=CharSet.Unicode]
extern "C" bool capGetDriverDescription(UInt16, StringBuilder^, int, StringBuilder^, int);
But in C++/CLI you can directly call the native C function without use P/Invoke: you can mix managed and unmanaged code.
Hope it helps!
|
|
|
|
|
Hello , why i cant return the char* something using the class like that.
struct random_class {
char *something;
void __thiscall classfunction (void *pParam);
};
random_class* pParam;
void (__thiscall* classfunction)(void *pParam );
void __thiscall myclassfunction(void *pParam )
{
classfunction(pParam->something);
}
error C2227: left of '->crypto_buf' must point to class/struct/union/generic type
1> type is 'void *'
|
|
|
|
|
nah1337 wrote: ->crypto_buf'
are you sure you've posted the correct section of code ? I cant see :-
nah1337 wrote: ->crypto_buf'
anywhere in that snippet you've posted, so I dont know what relevance it has to your issue ...
'g'
|
|
|
|
|
Yeah was mine mistake it should look like this:
struct random_class {
char *crypto_buf;
void __thiscall classfunction (void *pParam);
};
random_class* pParam;
void (__thiscall* classfunction)(void *pParam );
void __thiscall myclassfunction(void *pParam )
{
classfunction(pParam->crypto_buf);
}
error C2227: left of '->crypto_buf' must point to class/struct/union/generic type
1> type is 'void *'
|
|
|
|