|
if you are creating a windows form application under CLR category then in Form1.h your code must be like this:
#pragma once
#include "Form2.h"
namespace CircularForm {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
.
.
.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2^ f2 = gcnew Form2();
f2->Show();
this->Close();
}
but when the form1 is closed the managed memory of form2 will be released. the whole program will be ended.
there is 2 way to do this:
1. don't close the form1, just hide form1 and when form2 is closed show it(form1) again.
2. add a new class (Form3) containing two objects (Form1 f1, Form2 f2). set it as startup form and control the f1,f2
sometimes 0 can be 1
|
|
|
|
|
Hi all,
Please help me to solve below problem:
1. First, I develop a 32bit application (include C#, VB, C++/CLI, C) in Vista 64bit with .NET framework 3.5, VS 2008. Everything runs ok.
a. C++/CLI, C: platform is Win32
b. C#, VB: platform is x86
2. Second, I continue convert above application to 64bit application and also run in Vista 64bit, .NET 3.5, VS 2008.
To converting, I change some main point as below:
a. C++/CLI: change platform from Win32 to x64, and pointer from 4bytes to 8bytes
b. C#, VB: change platform from x86 to Any CPU.
Everything builds ok, but when run application, unhandled exception was thrown everytime it call constructor of C++/CLI object:
- Message: "System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
- Stack Trace: " at ProjCS.Form1..ctor()
at ProjCS.Program.Main() in N:\test\Test64\ProjCS\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()"
I try to re-install VS 2008 and googling but still cannot find solution.
Anyone who has experience about problem, please help me to find root cause and solution to solve it.
Thanks a lot.
|
|
|
|
|
Hi everybody,
Please take you time to help me. Currently, I must solve it as soon as possible!
|
|
|
|
|
I want to write an event which is triggered when a file is created in a particular directory and then do rest of things.
Naveen
|
|
|
|
|
|
Hello folks,
Can someone help me with this question: How can I make this work?
<br />
#include "stdafx.h"<br />
using namespace System;<br />
<br />
public ref class classX<br />
{<br />
private:<br />
classY ^m_refClassY;<br />
<br />
public:<br />
classX()<br />
{<br />
this->m_refClassY = gcnew classY();<br />
}<br />
};<br />
<br />
public ref class classY<br />
{<br />
private:<br />
classX ^m_refClassX;<br />
public:<br />
classY()<br />
{<br />
this->m_refClassX = gcnew classX();<br />
}<br />
};<br />
<br />
int main(array<System::String ^> ^args)<br />
{<br />
Console::WriteLine(L"Hello World");<br />
return 0;<br />
}<br />
Always when I try to compile this source, this error comes up.
cross_reference.cpp(10) : error C2143: syntax error : missing ';' before '^'
cross_reference.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
cross_reference.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
cross_reference.cpp(15) : error C2039: 'm_refClassY' : is not a member of 'classX'
cross_reference.cpp(8) : see declaration of 'classX'
cross_reference.cpp(15) : error C2061: syntax error : identifier 'classY'
|
|
|
|
|
Forward declaration is the solution for circular dependencies. See the corrected code
ref class classY;
public ref class classX
{
private:
classY ^m_refClassY;
public:
classX();
};
public ref class classY
{
private:
classX ^m_refClassX;
public:
classY();
};
classX::classX(){
this->m_refClassY = gcnew classY();
}
classY::classY(){
this->m_refClassX = gcnew classX();
} In a real application, try to move the classes into separate files.
|
|
|
|
|
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
|
|
|
|
|