|
how to run on threat i am new to this.. kindly gv me some example plz...
|
|
|
|
|
Below is my coding.. i not sure where to put the thread....
#pragma once
#include "QUARANTINE.h"
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 Enhan_GUI {
public ref class manscan : public System::Windows::Forms::Form
{
public:
manscan(void)
{
InitializeComponent();
}
protected:
~manscan()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::GroupBox^ gbxfunction;
private: System::Windows::Forms::Button^ cmdPause;
private: System::Windows::Forms::Button^ cmdStart;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ cmdClose;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label3;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(manscan::typeid));
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->gbxfunction = (gcnew System::Windows::Forms::GroupBox());
this->cmdPause = (gcnew System::Windows::Forms::Button());
this->cmdStart = (gcnew System::Windows::Forms::Button());
this->label2 = (gcnew System::Windows::Forms::Label());
this->cmdClose = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->gbxfunction->SuspendLayout();
this->SuspendLayout();
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(47, 222);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(75, 75);
this->pictureBox1->TabIndex = 18;
this->pictureBox1->TabStop = false;
this->gbxfunction->Controls->Add(this->cmdPause);
this->gbxfunction->Controls->Add(this->cmdStart);
this->gbxfunction->Location = System::Drawing::Point(31, 76);
this->gbxfunction->Name = L"gbxfunction";
this->gbxfunction->Size = System::Drawing::Size(118, 107);
this->gbxfunction->TabIndex = 14;
this->gbxfunction->TabStop = false;
this->gbxfunction->Text = L"Functions";
this->cmdPause->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
this->cmdPause->Location = System::Drawing::Point(19, 66);
this->cmdPause->Name = L"cmdPause";
this->cmdPause->Size = System::Drawing::Size(75, 23);
this->cmdPause->TabIndex = 2;
this->cmdPause->Text = L"Pause";
this->cmdPause->UseVisualStyleBackColor = true;
this->cmdPause->Click += gcnew System::EventHandler(this, &manscan::cmdPause_Click);
this->cmdStart->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
this->cmdStart->Location = System::Drawing::Point(19, 37);
this->cmdStart->Name = L"cmdStart";
this->cmdStart->Size = System::Drawing::Size(75, 23);
this->cmdStart->TabIndex = 1;
this->cmdStart->Text = L"Start";
this->cmdStart->UseVisualStyleBackColor = true;
this->cmdStart->Click += gcnew System::EventHandler(this, &manscan::cmdStart_Click);
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->Location = System::Drawing::Point(259, 50);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(165, 16);
this->label2->TabIndex = 16;
this->label2->Text = L"Number of Files Scanned :";
this->cmdClose->Location = System::Drawing::Point(491, 408);
this->cmdClose->Name = L"cmdClose";
this->cmdClose->Size = System::Drawing::Size(75, 23);
this->cmdClose->TabIndex = 15;
this->cmdClose->Text = L"Close";
this->cmdClose->UseVisualStyleBackColor = true;
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Bodoni MT Poster Compressed", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(27, 16);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(123, 26);
this->label1->TabIndex = 13;
this->label1->Text = L"Click \'Start\' to Scan";
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(426, 52);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(13, 13);
this->label3->TabIndex = 17;
this->label3->Text = L"0";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(592, 447);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->gbxfunction);
this->Controls->Add(this->label2);
this->Controls->Add(this->cmdClose);
this->Controls->Add(this->label1);
this->Controls->Add(this->label3);
this->Name = L"manscan";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Sparta AV : Manual Scan";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->gbxfunction->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void cmdStart_Click(System::Object^ sender, System::EventArgs^ e) {
int count =0;
int t=0;
int refre=0;
int refres=0;
string namefile[100];
keeper=0;
ListBox^ listBox1 = gcnew ListBox;
SQLiteConnection ^connection = gcnew SQLiteConnection("Data Source=test.db3;Pooling=True");
connection->Open();
SQLiteCommand ^cmd = gcnew SQLiteCommand(connection);
cmd->CommandText = ("select * from keep");
SQLiteDataReader ^reader = cmd->ExecuteReader();
while (reader->Read())
{
String^ namekeep1 = gcnew String(reader->GetString(0));
MarshalString(namekeep1,namefile[t]);
t++;
}
reader->Close();
cmd->CommandText = ("drop table keep");
cmd->ExecuteNonQuery();
cmd->CommandText = ("create table temp(scanid DATETIME,filename VARCHAR(250),wormname VARCHAR(50),wormtype VARCHAR(50))");
cmd->ExecuteNonQuery();
listBox1->Size = System::Drawing::Size( 392, 319 );
listBox1->Location = System::Drawing::Point( 174, 76 );
this->Controls->Add( listBox1 );
listBox1->MultiColumn = false;
listBox1->SelectionMode = SelectionMode::MultiExtended;
for(int v=0;v<=t;v++)
{
vector<wstring> files;
std::wstring str2(namefile[v].length(), L' ');
std::copy(namefile[v].begin(), namefile[v].end(), str2.begin());
wstring directory = str2;
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();
label3->Text =count.ToString();
label3->Update();
refre++;
}
}
}
if (keeper==0)
{
System::Windows::Forms::MessageBox::Show(" No Virus is Found \n\n Your Drive is Clean");
}
if(keeper != 0)
{
System::Windows::Forms::MessageBox::Show("Number Of Virus Found : " + keeper);
}
connection->Close();
#if defined(DEBUG)
System::Diagnostics::Debug::WriteLine( listBox1->SelectedItems[ 1 ] );
System::Diagnostics::Debug::WriteLine( listBox1->SelectedIndices[ 0 ] );
#endif
Form^ form3 = gcnew QUARANTINE();
Form::Close();
form3->Show();
}
private: System::Void cmdPause_Click(System::Object^ sender, System::EventArgs^ e) {
system("PAUSE");
}
};
}
|
|
|
|
|
your code is too long and i haven't enough time to read it all. but below is the way to use a thread:
my form has two button named "buttonStart" and "buttonStop" when i press the first one my thread starts and when press the second one my thread stops. this is my code :
private: Thread^ myThread;
private: static volatile bool stop;
private: System::Void buttonStart_Click(System::Object^ sender, System::EventArgs^ e) {
myThread = gcnew Thread(gcnew ThreadStart( &Form1::Function ));
stop = false;
myThread->Start();
buttonStart->Enabled = false;
}
private: System::Void buttonStop_Click(System::Object^ sender, System::EventArgs^ e) {
stop = true;
buttonStart->Enabled = true;
}
public: static void Function()
{
MessageBox::Show("thread is now starting");
do
{
}
while(stop == false);
MessageBox::Show("thread stoped");
}
you can add some extra controls to your form and see that when you press the start button your controls will be alive. my function has a infinite loop and if you run it without threads your UI hangs.
however, i suggest you to read these:
Thread Class[^]
Threading tutorial[^]
to get a clean understanding of threads. and there are many perfect articles of threading in CP[^]:
1 2 3 4 5
sometimes 0 can be 1
modified on Wednesday, March 25, 2009 5:37 PM
|
|
|
|
|
I am trying to access a c++ created DLL from within Excel, with semi-success only:
I've followed the following tutorial EXACTLY: http://newtonexcelbach.wordpress.com...ng-excel-to-c/
Now, when I try and use the dll-functions that I've declared in the VB code, the function GetPrice(), which takes no arguments and simply returns a number, works fine.
However, as soon as I create a dll-function which takes input arguments, I get a #VALUE error in the cell in Excel ("A value used in formula is of the wrong data type" ).
I've downloaded the complete sample from the URL above and get the same error when running it (after recalculating the formulas).
I've created a test 'proxy' function (in which the code can be stepped through, which calls the dll function) to ensure that values sent to the dll function are indeed of type double and that seems to be the case ...
This guy seems to have had the same problem, however no solution was posted:
http://www.ozgrid.com/forum/showthread.php?t=54245[^]
Any help / tips would be greatly appreciated!
g
excell dll newbie
|
|
|
|
|
I have compiled the libtorrent library in an Visual Studio 2008 mfc dll project. I want to use this dll via an import library in a managed exe console application also developed in VS 2008.
The managed application project compiles ok. But when I try to run it I get the following assertion failed error message:
Debug Assertion Failed!
File: F:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dllinit.cpp
Line: 587
And when I press ignore I get the the following assertion failed error message
Debug Assertion Failed!
File: F:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dllmodul.cpp
Line: 137
After I press again the application works fine.
Althogh the path for the above files is not correct these files do exist in the following folder on my system
C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc
The following line in dllinit.cpp is cuasing the first assertion failiure:
ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
And the following line in dllmodul.cpp is cuasing the second assertion failure:
VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) ==
&afxModuleState);
Can any one help me out as to why these assertion failures are ocurring and how to resolve them?
|
|
|
|
|
Hi,
I'm having the same problem. Do you have found a solution by any chance ?
|
|
|
|
|
The bug has nothing to do with unmanage or managed interoperatability. The bug is somewhere in the Libtorrent Library but I cant seem to find the place of error.
|
|
|
|
|
Hey, I am trying to open form2 from form1. Then open a new form1 when form2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong, not sure I followed the correct syntax since all of the code is in the header files - the automatically generated code for Forms and controls.
/*Form1.h*/
#pragma once
#ifndef First
#define First
#include "Form2.h"
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
|
|
|
|
|
Your post is wrong on so many levels it's difficult to know where to start.
First, it is obvious you are a beginner. I don't know of any authoritative source for this but common sense tells me that Managed C++ development is not appropriate for beginners. Beginners probably need to learn C/C++ basics and consider CLI an advanced topic.
Next, as a user, if an application is popping up windows all the time I am closing it and uninstalling it. There is absolutely no need to open up new top level windows just to display a different view. Tabs are also grossly abused, from an MDI or Configuration perspective they make sense, but not as a Primary UI design.
Another thing, if you insist on this insanely poor path, the fundamental solution to a circular dependency problem is to introduce a third item to the picture and define the relationships such that the original two items are unrelated.
item one item two
\ /
\ /
\ /
new item
One other thing, you might want to start learning what Software Design Patterns are.
Good luck
modified on Tuesday, March 24, 2009 1:01 PM
|
|
|
|
|
Wow, talk about confused. For someone who doesn't know the answer you sure have a lot to say. Clearly, you misunderstand an attempt to simplify an example. As such you should consider not "answering" (loosely used, in your case) to people's posts.
|
|
|
|
|
thenutz72 wrote: Wow, talk about confused.
Ok, let's talk about that. What are you confused about?
thenutz72 wrote: For someone who doesn't know the answer
Um, "the answer"? Really, there is only one way to solve your problem, interesting. What part of my post does not qualify as an answer?
thenutz72 wrote: you should consider not "answering"
First lets get one thing clear. So far there is not one thing you have said that I would consider let alone that suggestion.
By the way if you continue to attempt to berate my reply it will end with me ripping your virtual head off and shoving it down your ignorant throat.
|
|
|
|
|
|
|
Mike is a well known here and has helpled lots of people, I suggeset you take what he has said constructively.
|
|
|
|
|
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 />
|
|
|
|
|