a question about the communication between C# and C++

  • Thread starter Thread starter Liu Guidong
  • Start date Start date
L

Liu Guidong

Dear friends,
I have a question about the communication between C# and
C++.
Can anyone help me ??
I have written a C# dll fies named "TestFordll2.dll",as
fllow:

using System;
namespace TestForDll2
{
public class TestForDll
{
private int result ;
public TestForDll()
{
result = 0;
}
public TestForDll(int a , int b)
{
result = 0;
result = a + b;
}
public int Out()
{
return result;
}
}
}

And I also wrote a C++ file named "Call.cpp" to call the
C# dll file "TestForDll2.dll",as follow:

#include <iostream.h>
#using <TestForDll2.dll>
#using <mscorlib.dll>
using namespace System;
using namespace TestForDll2;
int main()
{
int i = 0;
TestForDll2::TestForDll *a = new
TestForDll2::TestForDll(1,2);
i = a->Out();
cout<<"the result is"<<i<<endl;

}
And I also set the properties of the C++ file by using the
follwo:
1. Open the project's Property Pages dialog box.
Properties.
2. Click the C/C++ folder.
3. Click the General property page.
4. Modify the Resolve #using References property making
it pointing to the "TestForDll2.dll" file
when I build the project ,everyting is ok.But when I run
the project ,an error occured :can not

find file or assembly "TestForDll2",or can not find one of
its relier"
why??
Can anyone hlep me? Thanks

reagrds,
Liu Guidong
 
Hi Liu,
You probably don't have TestForDll2.dll in the PATH so the runtime cannot
find it. Try putting it in the same directory where the C++ .exe is.

--
Keiji Oenoki
Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.

--------------------
 
Back
Top