all groups > visual c libraries > july 2003 >
You're in the

visual c libraries

group:

a question about communication between C# and C++


a question about communication between C# and C++ Liu Guidong
7/14/2003 8:36:22 PM
visual c libraries:
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

Re: a question about communication between C# and C++ mullin NO[at]SPAM vibrant3d.com
7/22/2003 12:51:56 PM
It may be that it simply can't find the dll.

Windows searchs for DLLS in your local directory and then the system path.
Make sure your dll and exe are in the same directory, then launch the exe
[quoted text, click to view]
AddThis Social Bookmark Button