|
the problem come from this -> "Login form -> open form1 form , and form1.h has the others #include files just like "test1.h" and ect."
the include file must be correct utilized cause they can lead to your problem.
in an ideal world you should include the .h files like in a tree:
super_main.h
/ \
main1.h main2.h
/ \
submain1_1.h submain1_2.h
where each .h have one .cpp with the operational code
-- or --
there are some workaround like
#ifndef
#define
....code....
#endif
to make life easier when implementing .h
|
|
|
|
|
Thanks for the reply !
Yes of course I usually write #ifndef ect. definition into header files, but it's not a problem with this... main issue of this is in the namespace... because my major project is in C++ CLI how's You know isn't the same what is pure C++ ( unmanaged probably ) so, i'm not able to declare object of pure class ( example : class Test; and in managed class : ref class { ... public : Test object; ) i understand how can i resolve this problem -> i should declare pointer of unmanaged class : Test *object into managed class. But unfortunately my supervisor ( he hasn't seen my project yet ) wants or requires use auto_ptr ( because of memory leak ) , so i use this "intelligent" pointer in namespace area :
namespace TestSpace
{
auto_ptr<test> object;
ref class ClassTest
{
object->...
};
}
and it works,
but main problem is when i compile this code , and i have main order with header files same to You , 'm receiving information about the same or two definitions ( already defined ). I noticed that i haven't this problem if i don't use or i don't declare all of objects , variables in namespace like above... i think it's because of declarations in namespace , Ideal solution would be place declarations into ref class and i think it won't be compile error , but how's i said unfortunately we can't declare auto_ptr in ref class because of unmanaged and managed code error , and this is infinite loop... if i hadn't seen on my supervisior i would have written this with usual pointers ... : Test *object in ref class and no problem for me... but i can't imagine what would be if my teacher see this solution...
Of course if you don't find any more precisely solution , i'll do this with convenient linker option : /FORCE and i don't see this error... but You know... it's just like an strong solution...
Thanks for help
|
|
|
|
|
Hi,
I am stuck on creating this batch file. I need it to delete the oldest file in a given directory.
I got it working except if the filename contains spaces, which is where I'm stuck.
Here's what I have so far
SET DIRTODELOLDESTFILE="C:\Documents and Settings\TEST001\Desktop\test\New Folder\"
FOR /F %%i IN ('DIR /A-D /B /O-D %DIRTODELOLDESTFILE%') DO SET DELETEME=%%i
DEL %DIRTODELOLDESTFILE%\%DELETEME%
When I try to use
DIR /A-D /B /O-D I see the complete filename, but it's not being saved properly..
If you try a directory with a filename "New Text Document.txt", the script would only pick up "New" but not the entire file name. However, DIR /A-D /B /O-D returns the full filename. I tried googling around, but just about every solution is to "use quotations"... this isn't the case if I don't know the filenames in my directory. If anyone ran into this, any help/clues would be nice
Thanks!
PS: I don't know if this is in the right section. If not, sorry in advance >.>
|
|
|
|
|
Hi,
of course this is not the right forum, it is not a language question.
try
FOR /F "delims=!" %%i IN ('DIR /A-D /B /O-D %DIRTODELOLDESTFILE%') DO SET DELETEME= %%i
it replaces the default delimiters (space and tab) by a character that won't appear in a file path.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks Luc!
That worked nicely. I needed to add some extra string manipulation at the end to handle quotes.
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
How do I make a managed c++ struct that will be usable in c# as an array, while still being able to be passed to unmanaged c++ as an array?
I've inserted a series of ???? where I'm at a loss for what to do.
In unmanaged c++ i have something akin to
//c++ static lib
typedef struct
{
double position[3];
double time;
} TimedPosition;
class DataProducer
{
public:
DataProducer(){};
~DataProducer(){};
void GetData( TimedPosition * tp, unsigned int count );
};
In managed code i then have
// c++/cli managed dll
public ref class mgdDataProducer
{
public:
// Allocate the native object on the C++ Heap via a constructor
mgdDataProducer() : m_Impl( new DataProducer) {}
// Deallocate the native object on a destructor
~mgdDataProducer() { delete m_Impl; }
protected:
// Deallocate the native object on the finalizer just in case no destructor is called
!mgdDataProducer() { delete m_Impl; }
/*-----------------------------------------------------------------------------------------*/
public:
int GetData( ????, unsigned int count )
{
m_Impl->GetData( ????, count );
}
private:
DataProducer * m_Impl;
};
Thanks in advance
-Troy
|
|
|
|
|
You will need a "managed" equivalent of both (or at least the second one):
1. native TimePosition and
2. native array of TimePosition instances
If the mgdDataProducer sees struct TimedPosition while compiling in /clr mode, the 1st one is not necessary, I think. I am assuming here that void GetData( TimedPosition * tp, unsigned int count ) should fill an c-style array with "count" TimedPosition instances, right?
The signature of managed "GetData" would be then:
C++/CLI:
void mgdDataProducer::GetData(array<TimedPosition>^ Data, unsigned& Count);
C#:
void GetData(TimedPosition[] Data, ref uint Count);
In your implementation of mgdDataProducer::GetData , you need to transfer the content of native c++ array to a managed array (collection.. whatever). There exist several possibilities to accomplish this, I bet there are some built in interoperability helpers for transfering all native c-like or std:: sequences, although I cannot find a direct link right now.
The simplest way is to call the unmanaged DataProducer with a local c-style array, and shuffle the (there created) TimedPosition instances into the managed array. You can also write reusable wrappers for unmanaged arrays and much more, look at the keywords cli interop, marshalling or similar. I would also try to avoid PInvoke or unsafe stuff...
Cheers,
Paul
modified on Thursday, June 3, 2010 9:08 AM
|
|
|
|
|
I'm trying to binary serialize a 2D array using [Serializable] and ISerializable. In Special constructor for deserialization, I can't deserialize my array. I don't know what the type in info->GetValue("something", ??Type::typeid) . This is my code :
[Serializable]
private ref class SerializedArrayClass : public ISerializable
{
public:
array<array<float>^>^ jaggedArray;
array<float, 2>^ genericArray;
Matrix^ matrixArray;
int width;
int height;
int nElement;
SerializedArrayClass(int width, int height)
{
this->width = width;
this->height = height;
}
InitArray()
{
}
protected:
SerializedArrayClass(SerializationInfo^ info, StreamingContext context)
{
this->width = safe_cast<int>(info->GetValue("width", int::typeid));
this->height = safe_cast<int>(info->GetValue("height", int::typeid));
this->jaggedArray = safe_cast<array<array<float>^>^>>(info->GetValue("jaggedArray", ??::typeid));
this->genericArray = safe_cast<array<float, 2>^>>(info->GetValue("genericArray", ??::typeid));
this->matrixArray = safe_cast<Matrix^>(info->GetValue("matrixArray", ??::typeid));
}
public:
virtual void GetObjectData(SerializationInfo^ info, StreamingContext context)
{
info->AddValue("width", this->width);
info->AddValue("height", this->height);
info->AddValue("jaggedArray", this->jaggedArray);
info->AddValue("genericArray", this->genericArray);
info->AddValue("matrixArray", this->matrixArray);
}
}
What is the correct Type for 2D array and Matrix object?
Thanks,
|
|
|
|
|
hi guys
i use vc++2008.net and i created a form included a rich text box with a few words
and i made a (button + textfield) to help me find a word that exist in the rich text box,but i dont know what is the code to help me?
and thank u all ..
|
|
|
|
|
Hi,
the RichTextBox class has a Find() method, so I suggest you read up on it for starters.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Access the text. If it's System::String, then you can use the IndexOf and Substring methods. Note that this is more than 10 times slower than C/C++ functions for very large strings, which is what I found out today when I rewrote a block of code to see if unmanaged version would be faster than the managed version for immutable System::String type.
|
|
|
|
|
I'm struggling for a couple of days now. i have two forms,
The main form and some popup form with textboxes.
I open the popupform from the mainform then fill in some information on
the popupform and send it with a button. When that button is clicked
the mainform has to detect it and grab the data from the popupform before closing it.
but so far i'm not able to get that click event from the popupform
i tried the following which will compile but does nothing:
rowpopup^ popup = gcnew rowpopup();
popup->button_savetoform->Click += gcnew EventHandler(this, &Main::add_new_item);
I got some advice to work with delegates and after a lot of reading and googling
i still couldn't find how to use it in this situation.
Does anyone have an idea?
|
|
|
|
|
the code you write is actually....working....so...if you write here or post as attachment the full code i will check what's wrong
|
|
|
|
|
OK, i wrote a little test program which does the same.
#pragma once
#include "form2.h"
namespace Test2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ testbutton;
private: System::Windows::Forms::Label^ testlabel;
private: System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
public:
void InitializeComponent(void)
{
this->testbutton = (gcnew System::Windows::Forms::Button());
this->testlabel = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
this->testbutton->Location = System::Drawing::Point(12, 326);
this->testbutton->Name = L"button_test";
this->testbutton->Size = System::Drawing::Size(75, 23);
this->testbutton->TabIndex = 0;
this->testbutton->Text = L"Test";
this->testbutton->UseVisualStyleBackColor = true;
this->testbutton->Click += gcnew System::EventHandler(this, &Form1::testbutton_click);
this->testlabel->AutoSize = true;
this->testlabel->Location = System::Drawing::Point(9, 19);
this->testlabel->Name = L"label_test";
this->testlabel->Size = System::Drawing::Size(35, 13);
this->testlabel->TabIndex = 1;
this->testlabel->Text = L"";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(382, 361);
this->Controls->Add(this->testlabel);
this->Controls->Add(this->testbutton);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
Form2^ popup = gcnew Form2();
popup->button_send->Click += gcnew System::EventHandler(this, &Form1::raised_event);
}
private:
#pragma endregion
private: System::Void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->ShowDialog();
}
private: void raised_event (System::Object^ sender, System::EventArgs^ e)
{
Form2^ popup = gcnew Form2();
testlabel->Text = popup->textbox->Text;
}
};
}
Form2
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace Test2 {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
protected:
~Form2()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::RichTextBox^ textbox;
protected:
public: System::Windows::Forms::Button^ button_send;
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textbox = (gcnew System::Windows::Forms::RichTextBox());
this->button_send = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->textbox->Location = System::Drawing::Point(12, 12);
this->textbox->Name = L"textbox";
this->textbox->Size = System::Drawing::Size(268, 147);
this->textbox->TabIndex = 0;
this->textbox->Text = L"";
this->button_send->Location = System::Drawing::Point(12, 165);
this->button_send->Name = L"button_send";
this->button_send->Size = System::Drawing::Size(75, 23);
this->button_send->TabIndex = 1;
this->button_send->Text = L"Send";
this->button_send->UseVisualStyleBackColor = true;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 198);
this->Controls->Add(this->button_send);
this->Controls->Add(this->textbox);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
textbox->Text = "hoi";
}
};
}
|
|
|
|
|
so....here we are:
in form 1 substitute:
private: System::Void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->ShowDialog();
}
private: void raised_event (System::Object^ sender, System::EventArgs^ e)
{
Form2^ popup = gcnew Form2();
testlabel->Text = popup->textbox->Text;
}
};
private:
Form2^ popup;
void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
popup = gcnew Form2();
popup->button_send->Click += gcnew EventHandler(this, &Form1::raised_event);
popup->ShowDialog();
}
void raised_event (System::Object^ sender, System::EventArgs^ e)
{
testlabel->Text = popup->textbox->Text;
}
i'm pretty sure you'll understand my changes.
Maybe it would be better to use delegates....i'll write you some code for that
#pragma once
#include "Form2.h"
namespace delete1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private:
void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->myPersonalDelegateCl += gcnew Form2::myPersonalDelegate(this,&Form1::raised_from_delegate);
popup->ShowDialog();
}
void raised_from_delegate (String ^txt)
{
this->testlabel->Text=txt;
}
System::Windows::Forms::Button^ testbutton;
System::Windows::Forms::Label^ testlabel;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->testbutton = (gcnew System::Windows::Forms::Button());
this->testlabel = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
this->testbutton->Location = System::Drawing::Point(12, 326);
this->testbutton->Name = L"button_test";
this->testbutton->Size = System::Drawing::Size(75, 23);
this->testbutton->TabIndex = 0;
this->testbutton->Text = L"Test";
this->testbutton->UseVisualStyleBackColor = true;
this->testbutton->Click += gcnew System::EventHandler(this, &Form1::testbutton_click);
this->testlabel->AutoSize = true;
this->testlabel->Location = System::Drawing::Point(9, 19);
this->testlabel->Name = L"label_test";
this->testlabel->Size = System::Drawing::Size(35, 13);
this->testlabel->TabIndex = 1;
this->testlabel->Text = L"";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(382, 361);
this->Controls->Add(this->testlabel);
this->Controls->Add(this->testbutton);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
};
}
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace Test2 {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
delegate void myPersonalDelegate(String ^txt);
myPersonalDelegate^ myPersonalDelegateCl;
protected:
~Form2()
{
if (components)
{
delete components;
}
}
private:
void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
textbox->Text = "hoi";
}
void button_send_Click(System::Object^ sender, System::EventArgs^ e) {
this->myPersonalDelegateCl(this->textbox->Text);
}
System::Windows::Forms::RichTextBox^ textbox;
System::Windows::Forms::Button^ button_send;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textbox = (gcnew System::Windows::Forms::RichTextBox());
this->button_send = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->textbox->Location = System::Drawing::Point(12, 12);
this->textbox->Name = L"textbox";
this->textbox->Size = System::Drawing::Size(268, 147);
this->textbox->TabIndex = 0;
this->textbox->Text = L"";
this->button_send->Location = System::Drawing::Point(12, 165);
this->button_send->Name = L"button_send";
this->button_send->Size = System::Drawing::Size(75, 23);
this->button_send->TabIndex = 1;
this->button_send->Text = L"Send";
this->button_send->UseVisualStyleBackColor = true;
this->button_send->Click += gcnew System::EventHandler(this, &Form2::button_send_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 198);
this->Controls->Add(this->button_send);
this->Controls->Add(this->textbox);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
this->ResumeLayout(false);
}
#pragma endregion
};
}
ps1 alway split code in .h and in .cpp
ps2 don't ever write personalized code between #pragma region Windows Form Designer generated code and #pragma endregion
modified on Friday, May 21, 2010 5:27 AM
|
|
|
|
|
The delegate works perfect Thank you
the other code raised the event but didn't get the information from the textbox.
so i'll study the delegate.
Just one quiestion you changed the namespace of Form1 this results in compiler errors.
is there a reason you did this?
|
|
|
|
|
it was just the name i used...so no reason for that
|
|
|
|
|
there is simplest way if you are still enterested
|
|
|
|
|
Hi ,
when i am trying to build managed c++ project in visual studio .net 2003 , i am getting this kind of
description in output window,and not able to generate .exe.
Microsoft (R) .NET Resource Generator
[Microsoft .Net Framework, Version 1.1.4322.2443]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Usage:
ResGen inputFile.ext [outputFile.ext]
ResGen /compile inputFile1.ext[,outputFile1.resources] [...]
Where .ext is .resX, .txt, or .resources
Converts files from one resource format to another. If the output
filename is not specified, inputFile.resources will be used.
The /compile option takes a list of .resX or .txt files to convert to
.resources files in one bulk operation, replacing .ext with .resources for
the output file name.
.txt files have this format:
# Use # at the beginning of a line for a comment character.
name=value
more elaborate name=value
and I am getting warnings like this
XtendedMenu warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetSegmentedProgressControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetSRPControl warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
NetSRPControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetBarGraphControl warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
NetBarGraphControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
The application is not generating .resources files in release build, where as in Debug build , i am getting same warnings ,still able to generate .exe. In release build not able to generate exe and resource files (.resources from .resx)
Any help is greatly appreciated.
Thanks,
sharada veena.
|
|
|
|
|
hello
i have to deliver a project to the doctor and i need a simple program or rich example in vc++.net please
& thank u all
|
|
|
|
|
Nobody here has the time to do your work for you. If you need a sample of some type of coding then look at the articles here on CodeProject and also use Google/Bing to search the internet.
It's time for a new signature.
|
|
|
|
|
Hi,
I have written a piece of code to save data from a Windows form in a file, and to read it from the file back into the Windows form. This works fine on the computer on which I've written the code (Windows 7). However, now I try to run the program on another computer (Windows XP), and a strange thing happens: when I read the data from the file, a rectangle character appeard at the end of each line.
When I write the data to the file, another such character is written to the file. So every time I save and read a file, an extra rectangle character is added. I'm using streamwriter / streamreader for the file input / output. Any idea how to prevent this strange behaviour?
|
|
|
|
|
Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed:
? sizeof(bool)
which gave me the message
error: identifier 'sizeof' out of scope
I can't seem to find documentation for this anywhere.
Thanks.
|
|
|
|
|
In C#, and in C++, sizeof is an operator, and not a function. It is something that is calculated at compile-time, and not at run-time. As such, the debugger does not know the sizeof operator, as it is a language-specific way of expressing an operator.
The way your type your expression, the debugger will interpret it as:
Call Debug.Print(sizeof(bool))
Since the sizeof function does not exist, you get an out of scope error message.
|
|
|
|
|