Dear all,
i tried to create a dll (with using c++/cli)and for this i did -
choose VC++ template ->CLR-> and choose Class Library for making a simple dll with a method sum. code is look like:- Header file code is:-
#pragma once
using namespace System;
namespace dll_for_sum {
public ref class Class1
{
public:
int sum( int x, int y );
};
}
.cpp code is :-
#include "stdafx.h"
#include "dll_for_sum.h"
int dll_for_sum::Class1::sum(int x, int y)
{
return x+y;
}
when i build it , it successfully build, here i get one dll_for_sum.dll in debug folder. now i want to use it in -visual studio -> new->choose and expand visual c++ template ->choose CLR -> *Window form application*
i want to call sum function on a button_click event.
Could any body tell me what files ( only .dll or .dll + dll_for_sum.h ) i need to paste in window application route folder to call sum function??????????
when i wondered i found - CLR->CLass Library is of type
c++/cli managed code so we only need .dll file to call it, here i set the ref of .dll in window application by using following step:-
For references i go ->Properties ->references->framework & references ->add new references ->then browse and choose .dll file.
after this on_button_click area I WROTE:-
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Class1 obj;
obj.sum(2,3);
}
};
or
Perhaps object is created by differently in c++/CLI so i wrote:-
Class1^ objectt = gcnew Class1();
objectt->sum(10,12);
here in both cases i got the error like :-
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\call_sum_method\call_sum_method\Form1.h(81): error C2065: 'Class1' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\call_sum_method\call_sum_method\Form1.h(81): error C2065: 'objectt' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\call_sum_method\call_sum_method\Form1.h(81): error C2061: syntax error : identifier 'Class1'
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\call_sum_method\call_sum_method\Form1.h(82): error C2065: 'objectt' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\call_sum_method\call_sum_method\Form1.h(82): error C2227: left of '->sum' must point to class/struct/union/generic type
Give me some way to come out with this problem