在vc中有 这样一个 函数typedef void * XDHANDLE;
//XpackDescribleFile 文件的路径 相当及绝对 都可以
BCCCLT_API  XDHANDLE NewXpackHandle(const char * XpackDescribleFile);我转成 .net 代码如下 /// <summary>
    /// 构件一个用于XPack数据交换的数据区
   /// </summary>
    /// <param name="path">XPack结构定义文件名,不能超过1024字节长</param>
    /// <returns>返回该XPack数据区的句柄;==0(NULL): 失败</returns>
    [DllImport("bccclt.dll", CharSet = CharSet.Auto )]
    public static extern IntPtr NewXpackHandle(  string path);不知道为什么 我在.net调用 始终 为0 路径我 都用绝对路径(在vc 可以 在.net 中不可以

解决方案 »

  1.   

    [DllImport("bccclt.dll", CharSet = CharSet.Auto )]
      public static extern IntPtr NewXpackHandle( byte[] path);

      public static extern IntPtr NewXpackHandle( char[] path);
      

  2.   

    [DllImport("bccclt.dll", CharSet = CharSet.Auto )]
      public static extern IntPtr NewXpackHandle( stringbuilder path);
      

  3.   

    看样子,你的方法问题不大。
    你试试加入调用约定stdcall 或 其他的方法试试。
    如果你有vc的编译代码的话,看看VC编译的时候使用的是哪种调用约定。
    在c#里使用同样的调用约定。
      

  4.   

      [DllImport("bccclt.dll", SetLastError=true)]中的 setalasterror 什么意思
      

  5.   

    只知道SetLastError 
    setalasterror 什么意思就不知道了。SetLastError 可以在异常\错误时设置一个时,指定一个错误号。
    这样在之后的GetLastError中可以知道是哪一类错误。Sets the last-error code for the calling thread.Syntax
    C++以带有颜色区分的格式查看复制到剪贴板打印void WINAPI SetLastError(
      __in  DWORD dwErrCode
    );
    void WINAPI SetLastError(
      __in  DWORD dwErrCode
    );Parameters
    dwErrCode [in] 
    The last-error code for the thread.Return Value
    This function does not return a value.Res
    The last-error code is kept in thread local storage so that multiple threads do not overwrite each other's values.Most functions call SetLastError or SetLastErrorEx only when they fail. However, some system functions call SetLastError or SetLastErrorEx under conditions of success; those cases are noted in each function's documentation. Applications can optionally retrieve the value set by this function by using the GetLastError function immediately after a function fails. Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no system error code has this bit set. If you are defining an error code for your application, set this bit to indicate that the error code has been defined by your application and to ensure that your error code does not conflict with any system-defined error codes.
      

  6.   

    public static extern IntPtr NewXpackHandle(string path) 改成
    public static extern IntPtr NewXpackHandle(IntPtr path)调用NewXpackHandle这个函数为:
    NewXpackHandle(Marshal.StringToHGlobalAnsi(path))我以前就这么用,没问题