__int16  __stdcall  IC_Read(HANDLE idComDev,__int16 offset,__int16 len,unsigned char * databuffer);[DllImport("dllanme")]
public static extern short IC_Read(IntPtr idComDev,short offset,short len,StringBuilder databuffer);

解决方案 »

  1.   

    看看这个例子
    using System;
    using System.Text;
    using System.Runtime.InteropServices;public class blah
    {
       [DllImport("C:\\temp\\test\\test.dll",
        CharSet=CharSet.Ansi,
        CallingConvention=CallingConvention.StdCall,
        SetLastError=true)]
        static extern void leggimet([In] String fName, 
                                    [Out] StringBuilder buf, 
                                    [In] UInt32 bufSize,
                                    [Out]StringBuilder extrainfo, 
                                    [Out]IntPtr resp);    public static void Main()
        {
            uint bufSize = 10;
            StringBuilder buf = new StringBuilder((int)bufSize);
            StringBuilder extraInfo = new StringBuilder(10); // Whatever is the max size of extrainfo.         
            int resp;        unsafe {
                leggimet("blah", buf, bufSize, extraInfo, new IntPtr(&resp));
            }        System.Console.WriteLine(buf);
            System.Console.WriteLine(extraInfo);
            System.Console.WriteLine(resp);
        }
    }-- Example dll source ----#include <stdio.h>void __stdcall leggimet(const char* fname, 
                           unsigned char* buf,
                           unsigned long bufSizem,
                           char* extraInfo,
                           long* resp)
    {
       printf("%s\n", fname);
       strcpy(buf, "Blah");
       strcpy(extraInfo, "Blah2");
       *resp = 10;
    }