ref 不知道行不行,你试一下吧

解决方案 »

  1.   

    are you using try/catch in C# when you call the method? no error messages?  are you sure you are calling the right method? use the dumpbin.exe tool in
    C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\binto see the real entry pointdumpbin -exports YourDLL.dlllook at an example here to see how to call stdcall method:http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=uuNaNF2BCHA.2768%40cpmsftngxa08
    or try1. TestDll.cpp://compile with a command like
    //vsvars32
    //cl /LD TestDll.cpp
    #include <iostream>
    using namespace std;extern "C"  {
        __declspec(dllexport) int __stdcall TestSTDCALL(char* s1, char* s2)
        {
            cout << "Hello World TestSTDCALL with externc C" << endl;
    cout << "argument 1:" << s1 << endl;
    cout << "argument 2:" << s2 << endl;
    return 1;
        }
    }
    __declspec(dllexport) int __stdcall TestSTDCALL_CPP(char* s1, char* s2)
    {
        cout << "Hello World TestSTDCALL_CPP" << endl;
        cout << "argument 1:" << s1 << endl;
        cout << "argument 2:" << s2 << endl;
        return 2;
    }2. TestCpp.cs:
    //use 
    //dumpbin -exports TestDll.dll
    //to find out the real function entry pointusing System;
    using System.Runtime.InteropServices;class Class1
    {
    [STAThread]
            static void Main(string[] args)
            {
                Console.WriteLine("Starting...");
                
                Console.WriteLine(TestSTDCALL("1st", "2nd"));
        
                Console.WriteLine(TestSTDCALL_CPP("first", "second"));            Console.Write("\n\nHit Enter Key to Quit...");
                Console.Read();
            } 
            [DllImport("testDLL.Dll", 
    CallingConvention=CallingConvention.StdCall)]
            public static extern int TestSTDCALL(string s1, string s2);        [DllImport("testDLL.Dll", EntryPoint="?TestSTDCALL_CPP@@YGHPAD0@Z", 
    CallingConvention=CallingConvention.StdCall)]
            public static extern int TestSTDCALL_CPP(string s1, string s2);
    }