|
In fact, my real source is in separate files, but I got the same problem.
Anyway, with your answer I figured out what to do in this case too.
Thanks.
|
|
|
|
|
Navaneeth (or anyone ,
I posted this under "Circular Form Reference" subject but it's a very similar question. I had tried to add 'ref class Form2;' but now get a 'no appropriate default constructor available'.
I was able to recreate my issue by simply creating two forms and adding a button to each that call the other form. So most of the code is the automaticly generated code from MS. I'm trying to keep the example simple by only incl. some code.
/*Form1.h*/
#pragma once
#ifndef First
#define First
#include "Form2.h"
ref class Form2;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2 ^ frm = gcnew Form2;
frm->Show();
this->Close();
}
#endif
/*Form2.h*/
#pragma once
#ifndef Second
#define Second
#include "Form1.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form1 ^ frm = gcnew Form1;
frm->Show();
this->Close();
}
#endif
modified on Tuesday, March 24, 2009 1:30 PM
|
|
|
|
|
You'll probably need to separate your code out of the H files into CPP files for
at least one of your classes.
#pragma once
ref class Form2;
ref class Form1 : public System::Windows::Forms::Form
{
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);
}
#include "Form1.h"
#include "Form2.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Form2 ^ frm = gcnew Form2;
frm->Show();
this->Close();
}
#pragma once
#include "Form1.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Form1 ^ frm = gcnew Form1;
frm->Show();
this->Close();
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
To do what do you want, you´ll have to do forward declaration, in the same way explained by Navaneeth.
<br />
<br />
#pragma once<br />
ref class Form2;
<br />
<br />
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);<br />
<br />
<br />
#include "Form1.h"<br />
#include "Form2.h"
<br />
System::Void Form1::button1_Click(System::Object^ sender, System::EventArgs^ e)<br />
{<br />
Form2 ^ frm = gcnew Form2;<br />
frm->Show();<br />
this->Close();<br />
}<br />
<br />
<br />
<br />
#pragma once<br />
#include "Form1.h"
<br />
<br />
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) <br />
{<br />
Form1 ^ frm = gcnew Form1;<br />
frm->Show();<br />
this->Close();<br />
}<br />
|
|
|
|
|
Hello all,
I create a monitor application that can sent email when trigger the alarm. But the McAfee block all the email by the rule "Prevent mass mailing worms from sending mail". Is there any way to create a customized rule or add my application into the exculde list when install it?
|
|
|
|
|
hi guys,
i am working on a worm scanner... most of the modules are done... but there is a problem regarding the pause button.. i not sure how to do it...
below is my coding :-
vector<wstring> files;
wstring directory =(L"C:\\Windows\\system32");
if (ListFiles(directory, L"*", files))
{
for (vector<wstring>::iterator it = files.begin(); it != files.end(); ++it)
{
keepname = WStringToString(it->c_str());
searchkmp();
int index = listBox1->Items->Add(String::Concat(gcnew String(it->c_str())));
listBox1->SelectedIndex = index;
count++;
listBox1->Update();
}
}</wstring></wstring>
when user click on start the program will get the filenames... each time it gets the filename it will call for the string matching function (searchkmp()) to match the for signature...
My question is how can i make a pause function in this program ya.. when user click on the pause the program should pause and when user click back on the same button it will continue....
kindly help me ya...
regards,
Thilek
|
|
|
|
|
I don't see anything in your post indicating a Managed C++/CLI question.
kindly help me ya...
Thilek wrote: My question is how can i make a pause function
Pausing and resuming threads might not seem as straight forward as you might think. It might interest you to know that older .NET frameworks had Thread.Pause/Resume but they were deprecated due to numerous problems (ok mostly user created problems). There are many resources you can read, you might start here[^]
Of course you don't actually have to pause/resume the threads because you can build into your system the functionality yourself. Meaning that you would upon your pause event actually stop the threads (gracefully of course) and then restart them on the resume event. This of course requires much work on your part.
modified on Monday, March 23, 2009 11:59 AM
|
|
|
|
|
well i am doing this program in .net... the entire program is done in managed C++ but there are some i had to use normal c++ since i am new to managed c++...
|
|
|
|
|
I yes. I missed the gcnew, among other things, in your first post. My fault.
|
|
|
|
|
hm.... how can pause them since when i am running the scan.. the form does not accept any events....
|
|
|
|
|
|
I should write a Windows32 form, in which I can input Unicode. When I create multiple instances of application.all the form must display some content, and When I change the content, the content in all instances must change according to the changed Unicode.
Now I can get the content of input, but how can I put the value into the variable in commen memory area?
#include "stdafx.h"
#include "windows.h"
#include <memory.h>
#include <TCHAR.h>
//#pragma once
#pragma data_seq("Shared")
volatile wchar_t* content;
#pragma data_seq()
#pragma comment(linker, "/Section:Shared,RWS")
namespace ShareMemory2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(67, 26);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(164, 20);
this->textBox1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(105, 64);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(296, 111);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private : System::String^ Pwchar_tToString(wchar_t* content){
System::IntPtr ptr(content);
System::String^ string = System::Runtime::InteropServices::Marshal::PtrToStringUni(ptr);
return string;
};
private : wchar_t *StringToPwchar_t(System::String^ str){
IntPtr ptr = System::Runtime::InteropServices::Marshal::StringToHGlobalUni(str);
wchar_t *string = reinterpret_cast<wchar_t*>(ptr.ToPointer());
return string;
};
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
/*wchar_t**/ content=TEXT("abc");
//memcpy((void*)content,content2,4);
wchar_t* cont2=TEXT("abc");
int i=0;
this->textBox1->Text=Pwchar_tToString(cont2);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
wchar_t* in=StringToPwchar_t(this->textBox1->Text);
int i=0;
}
};
}
|
|
|
|
|
when I compile the code, VS always display :warning LNK4039: section 'Shared' specified with /SECTION option does not exist.
I look up some solution suggesting initializing variable, so I verify to
#pragma data_seq("Shared")
volatile wchar_t content[20]=TEXT("abc");
#pragma data_seq()
But the problem still exists.
|
|
|
|
|
Try initializing the variable...
#pragma data_seg(push, shared1, ".Shared")
volatile wchar_t* content = 0;
#pragma data_seg(pop, shared1)
#pragma comment(linker, "/Section:.Shared,RWS")
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Compiler Error C2393
Error Message
'symbol' : per-appdomain symbol cannot be allocated in segment 'segment'
The use of appdomain variables implies that you are compiling with /clr:pure or /clr:safe, and a safe or pure image cannot contain data segments.
See /clr (Common Language Runtime Compilation) for more information.
Example
The following sample generates C2393.
Copy Code
// C2393.cpp
// compile with: /clr:pure /c
#pragma data_seg("myseg")
int n = 0; // C2393
------------------------------------------------------------------------------------
This is the explaination of MSDN,but I don't know how to resolve it
|
|
|
|
|
So you are asking us what to do about the compiler error, again?
So someone here could post a few sentences that would eliminate that error an introduce you to the next problem you will not understand.
This is an internet forum not an instructor lead programming class. Therefore some topics are to long and complex to be appropriate for an internet forum. This is one of them. The bottom line is that you need to study the technologies you are attempting to work with until you understand them well enough that that compiler message would not cause you to blindly post it into internet forums.
|
|
|
|
|
ernst20020530 wrote: a safe or pure image cannot contain data segments.
Seems fairly clear to me...what else do you need to know?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have installed a mouse hook to trap any mouse action on my application. The hook is installed at OnCreate function of MDI frame using.
m_hMouseHook = ::SetWindowsHookEx(WH_MOUSE, MouseHookProc, NULL, ::GetCurrentThreadId());
And in MouseHookProc function:
LRESULT CMainFrame:: MouseHookProc (int nCode, WPARAM wParam, LPARAM lParam )
{
CMainFrame* pThis = (CMainFrame*)AfxGetMainWnd();
if (nCode < 0) // do not process message
return CallNextHookEx(pThis->m_hKeyHook, nCode, wParam, lParam);
EnterCriticalSection(&(pThis->m_Lock));
pThis->m_nTimerCount = 0;
LeaveCriticalSection(&(pThis->m_Lock));
return CallNextHookEx(pThis->m_hKeyHook,nCode,wParam,lParam);
}
Now, the mouse hook behaving as expected except when I am hovering the mouse on menu items means if open the File menu item and moving the mouse on the menu items available under File menu then the hook is not working (MouseHookProc function is not handled).
Please any one provide any suggestion/idea.
Thanks in advance.
Sandip
|
|
|
|
|
Using the MenuStrip and OpenFileDialog controls with Windows Forms, I can read a data file (openFiledialog) and store the numerical day in an array. But I can't figure out how to access the data stored in the array from another control, for example from the button control using the click event handler? I would be greatly relieved if someone can help me figure how to do this. Many thanx,
eddy
|
|
|
|
|
isaaks wrote: But I can't figure out how to access the data stored in the array from another control, for example from the button control using the click event handler?
What is the scope of that array? If it has a class level scope, you should be able to access it from event handler.
|
|
|
|
|
Thanx for your reply. The array is a managed array (array<float>^ xx = gcnew array<float>(100)) but I don't know how to give it class scope. However, I found that an array (using pointers) with global scope seems to work (float *xx = new float[100]).
|
|
|
|
|
Hard to tell more without seeing the code.
|
|
|
|
|
Hello, thanks for looking at this!
I am a fairly new programmer just trying to learn new things so try to bear with me.
Here is my problem:
I don't know how to code something that creates new variables that store values that change per repetition of a loop.
To clarify, here is my situation:
I am building a math flashcard program that has 3 forms. The first is irrelevant to the question. The second form uses the rand() function to make up 2 numbers for the user to either add or subtract, they enter their answer into a textbox and then hit a button that stores their answer and gives them new numbers to work with (this happens 10 times). The third box is supposed to display the questions and correct answers of the randomly generated questions.
Further clarification of my problem using an example of what happens to me:
1st Iteration of loop starts:
1. Random number generator gives the numbers 2 and 3 for the user to add
2. User enters 5 and hits the continue button
3. The continue button stores the numbers 2, 3, and 5 as variables named "1num", "2num", and "ans" respectively.
2nd Iteration of loop starts:
4. The button gives the user new numbers
5. Random number generator gives the numbers 4 and 5 for the user to add
6. User enters 9 and hits continue button
7. The continue button overwrites the previous values for "1num" 2num and "ans" with 4, 5, and 9
So on so forth
I hope I am being clear enough on what my problem is.
Basically I think I need to include something in the loop that makes new variables to store the new values so it doesn't overwrite previous ones.
Oh boy that was fun to try to explain. If there is any confusion feel free to ask questions.
Thanks for any help!!!
***Oh Geez! Edit***
So after coding some, I realized that I can't even get my program to open the other forms correctly, I have:
#include "DoMath.h"
Form^ DoMath = gcnew Form();
DoMath->Show();
and that opens up a new form when I hit the button on my first form, but its just a blank form, its not my DoMath form. Uhg, I just googled this and tried like 10 different ways, and all of them either don't work or do the same exact thing my code does. It would be much appreciated if someone could give me the correct code for this.
modified on Sunday, March 15, 2009 4:14 AM
|
|
|
|
|
TabascoSauce wrote: The continue button overwrites the previous values for "1num" 2num and "ans" with 4, 5, and 9
Create a type which can store all these 3 values. Create a new instance of this type each time and keep it in a generic list. If you iterate over this list, you get all the answers user given. To explain what I said, create a class something like the below.
ref class QA{
public:
QA(int f, int s, int input)
: firstNumber(f)
, secondNumber(s)
, userInput(input)
{}
property int FirstNumber{
int get(){
return firstNumber;
}
}
property int SecondNumber{
int get(){
return secondNumber;
}
}
property int UserInput{
int get(){
return userInput;
}
}
private:
int firstNumber, secondNumber, userInput;
}; In the loop, create a QA instance and add it to a List(QA) .
using namespace System::Collections::Generic;
List<QA^>^ qaList = gcnew List<QA^>();
qaList->Add(gcnew QA(FirstRandomNumber,SecondRandomNumber,UserInput));
TabascoSauce wrote: Form^ DoMath = gcnew Form();
DoMath->Show();
and that opens up a new form when I hit the button on my first form
Looks like you are not clear with the object oriented concepts. The above code creates form instance each time it is executed. You need to make the form object as a class level variable if you don't want it to be created each time.
|
|
|
|
|
**Edit**
Oh wow after doing a ton of research and reading I got everything to work!
Thank you very much!
modified on Sunday, March 15, 2009 8:22 PM
|
|
|
|
|