|
This[^] is the best place for MFC related questions.
|
|
|
|
|
hi !! can some one help me too Write a program like patchwork that takes two characters c and d, and a positive integer n and displays the following object made of the characters c and d over n
lines and n columns, as shown below.
(in for loop if that posible)
Sample 1:
Enter two characters and an integer: $ * 3
$*$
*$*
$*$
Sample 2:
Enter two characters and an integer: / \ 6
/\/\/\
\/\/\/
/\/\/\
\/\/\/
/\/\/\
\/\/\/
=======================================
i have tried something like this
#include
using namespace std;
int main() {
int n;
char c1, c2;
cout << "Enter two characters and an integer: " << flush;
cin >> c1 >> c2 >> n;
for (int i = 2; i < n; i++)
{
cout >> c1 >> c2;
}
return 0;
}
========================================
and
#include
using namespace std;
int main() {
int n;
char c1, c2;
cout << "Enter two characters and an integer: " << flush;
cin >> c1 >> c2 >> n;
for (int i = 2; i < n; i++)
{
cout << c1 << c2 << endl;
for (int j = 2; j <= n-1 ; j++)
cout << c2 << c1 ;
cout << endl;
}
return 0;
}
=============================<pre>
but it turn ot to be different to what i want and i dont know what to do next .
|
|
|
|
|
|
I like to create an application which reads and writes data from a specific set of binary files. I choose C++/CLI because it’s easy to create a GUI with .Net but the file format is documented in c++ header files (.h).
File format is the following: Header, Header2, Data, Import, Export
Header is:
<br />
class fHeader {<br />
DWORD Id1;<br />
DWORD Id2;<br />
DWORD Id iSig;<br />
DWORD iCrc;<br />
DWORD iCompression;<br />
DWORD iFlags;<br />
LWORD iDataSize;<br />
DWORD iImportSize;<br />
DWORD iExportSize;<br />
}<br />
My idea is the following:
MBinaryFile::MBinaryFile(String^ name)<br />
{<br />
this->FileName = name;<br />
<br />
OriginalFileHeader = gcnew array<Byte>(sizeof(fHeader));<br />
<br />
FileStream^ fs = gcnew FileStream(this->FileName, FileMode::Open, <br />
FileAccess::Read);<br />
<br />
BinaryReader^ br = gcnew BinaryReader(fs);<br />
OriginalFileHeader = br->ReadBytes(OriginalFileHeader->Length);<br />
<br />
pin_ptr<Byte> pHeader = &OriginalFileHeader[0];<br />
fHeader* iOrigHdr = reinterpret_cast<fHeader*>(pHeader);<br />
<br />
Data = gcnew array<Byte>(iOrigHdr->iDataSize);<br />
Data = br->ReadBytes(Data->Length);<br />
}<br />
The problem with this approach is that every time I need to change the header I have to convert it to C++ as the pin_ptr is not able to be used as a class variable.
<br />
MBinaryFile::ChangeFlags(DWORD newFlags)<br />
{<br />
pin_ptr<Byte> pHeader = &OriginalFileHeader[0];<br />
fHeader* iOrigHdr = reinterpret_cast<fHeader*>(pHeader);<br />
<br />
iOrigHdr->iFlags = newFlags; <br />
}<br />
Creating the Header as a .Net class would be another option but I also need that to work for Header2. Header2 is a much larger C++ class with inline functions so I don’t want to convert all of the members and (inline) methods.
Is pin_ptr the way to go or is there a better way to deal with this problem?
Thanks for your help!
|
|
|
|
|
atzplzw wrote: a specific set of binary files.
all files are binary.
atzplzw wrote: My idea is the following:
What you posted after that is source code, not an idea.
Here is an idea:
Use the native C structure and native code to read the files into native memory. Then copy the values into managed memory (something CLI makes very easy in the case of doubles). This way there won't be any pinning required.
|
|
|
|
|
i guys ,
i am running a threat which will scan for worm in given directories..
currently its scanning but it supposed to show the scanned files in the listbox.. but its not showing.. how can i make it to show on list box ya..
Below is my coding :-
#pragma once
#include "Form1.h"
#include "QUARANTINE.h"
#include "Scanner.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data::SQLite;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Threading;
char status ='S';
namespace Enhan_GUI {
public ref class autoscan : public System::Windows::Forms::Form
{
public:
autoscan(void)
{
InitializeComponent();
}
int Data;
protected:
~autoscan()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ cmdClose;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ cmdPause;
private: System::Windows::Forms::GroupBox^ gbxfunction;
private: System::Windows::Forms::Button^ cmdStart;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(autoscan::typeid));
this->cmdClose = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->cmdPause = (gcnew System::Windows::Forms::Button());
this->gbxfunction = (gcnew System::Windows::Forms::GroupBox());
this->cmdStart = (gcnew System::Windows::Forms::Button());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->gbxfunction->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
this->cmdClose->Location = System::Drawing::Point(491, 408);
this->cmdClose->Name = L"cmdClose";
this->cmdClose->Size = System::Drawing::Size(75, 23);
this->cmdClose->TabIndex = 9;
this->cmdClose->Text = L"Close";
this->cmdClose->UseVisualStyleBackColor = true;
this->cmdClose->Click += gcnew System::EventHandler(this, &autoscan::cmdClose_Click);
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 = 6;
this->label1->Text = L"Click \'Start\' to Scan";
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, &autoscan::cmdPause_Click);
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 = 7;
this->gbxfunction->TabStop = false;
this->gbxfunction->Text = L"Functions";
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, &autoscan::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 = 10;
this->label2->Text = L"Number of Files Scanned :";
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 = 11;
this->label3->Text = L"0";
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 = 12;
this->pictureBox1->TabStop = false;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::Control;
this->ClientSize = System::Drawing::Size(592, 447);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->label3);
this->Controls->Add(this->cmdClose);
this->Controls->Add(this->label1);
this->Controls->Add(this->gbxfunction);
this->Controls->Add(this->label2);
this->Name = L"autoscan";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Sparta Av : Auto Scanning";
this->gbxfunction->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void cmdStart_Click(System::Object^ sender, System::EventArgs^ e) {
autoscan^ w = gcnew autoscan;
w->Data = 42;
Thread^ newThread = gcnew Thread( gcnew ThreadStart( w,&autoscan::ThreadFunction ) );
newThread->Start();
}
private: System::Void cmdPause_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void cmdClose_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
void autoscan::ThreadFunction()
{
autoscan::threat();
}
void threat()
{
int count =0;
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 = ("drop table temp");
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;
vector<wstring> files;
wstring directory =(L"C://NVIDIA");
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();
listBox1->Refresh();
label3->Text =count.ToString();
label3->Update();
}
}
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);
}
#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();
}
};
}
|
|
|
|
|
its ok guys... i manage to solve that.. thanks anyway...
cheers.....
|
|
|
|
|
hi !! can some one help me to Write a C++ program like patchwork that takes two characters c and b, and a positive integer n and displays the following object made of the characters c and d over n
lines and n columns, as shown below.
(in for loop if that posible)
Sample 1:
Enter two characters and an integer: $ * 3
$*$
*$*
$*$
Sample 2:
Enter two characters and an integer: / \ 6
/\/\/\
\/\/\/
/\/\/\
\/\/\/
/\/\/\
\/\/\/
......................................................
This is what i have tried
---------------------
#include
using namespace std;
int main() {
int n;
char c, b;
cout << "Enter two characters and an integer: " << flush;
cin >> c >> b >> n;
for (int i = 2; i < n; i++)
{
cout << c << b;
}
return 0;
}
-----------
but i have no ideas waht to do next...
|
|
|
|
|
hi guys,
i am having program when i minimize then maximize a form that running a job..
My program will scan for worms in the selected directories.. when i click start it will start scanning .... while scanning it will add the scanned file names into a listbox.... if i minimize the form or open anothe windows or application (lets say my document)then click back on the form , its not showing the contents on the list box.. the list box is empty till the whole scanning process is completed...
How can i make it show the list (refresh) even after i minimize it and show it back....
and my second question is how i can allow the form to accept click on others buttons while its still scanning.. this is to allow me to stop a the scanning.... if i click on close it waits till the scanning to complete before it close...
Kindly help me...
|
|
|
|
|
Run the scanning in a separate thread. It will solve your two problems.
|
|
|
|
|
yes. if your program works in a loop, the only whey to keep your UI alive is to use the Thread.
write youre loop in a function and then run it on a thread.
sometimes 0 can be 1
|
|
|
|
|
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.
|
|
|
|
|