>>>long f(long i) {return i; }。the problem is that the size of long in C++ (4 bytes) is different from size of long in C# (8 bytes), try to use int instead
Simple.cpp:#include <iostream.h>#include <iostream.h>extern "C"  
{    __declspec(dllexport) long f(long i) 
    {
        cout << "int f(int)" << " sizeof long :" << sizeof(long) << endl;
return i;
    }
}compile:
cl /LD Simple.cppTestSimple.cs:using System;
using System.Runtime.InteropServices;class TestSimple
{
        static void Main(string[] args)
        {
    int i=101;
    Console.WriteLine(f(i));
        }        [DllImport("Simple.dll")]
        public static extern int f(int i);
}

解决方案 »

  1.   

    as for the debug problem, what os are you using?seeINFO: Web Project Requirements for Visual Studio .NET Development
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;312073INFO: Common Errors When You Debug ASP.NET Applications in Visual Studio .NET
    http://support.microsoft.com/default.aspx?scid=KB;en-us;q306172