C#使用Intptr参数

时间:2018-03-05 02:40:31

标签: c# com x86 intptr

  1. 最近的64位应用程序解决了调用32位dll的问题,想用Com的过程来解决,编写了相应的Demo,当接口方法参数是string或int程序时可以正常运行,但是类型IntPtr
  2. 时,接口方法的参数包含程序错误

    2.com接口方法:

    public void TestPtr(IntPtr p)
    {
        string ss = Marshal.PtrToStringBSTR(p);
        MessageBox.Show("1111111111" + ss);
    }
    

    外部电话:

     System.Type t = Type.GetTypeFromProgID("TestComServer.TestComVisibleClass");
        dynamic o = Activator.CreateInstance(t);
        string iCameraID = txtCameraIndexCode.Text;//"12345678001310000017";
        System.IntPtr ptrCertFile = Marshal.StringToBSTR(iCameraID);
        o.TestPtr(ptrCertFile);  
    

    3.错误内容

      

    InvalidCastException的

    enter image description here

    4.由于他们自己的技术涉及到小白色的com,有一个愚蠢的尝试Intptr进入int32,然后转换为服务器中的Int服务器,失败

    请帮忙解决,谢谢

0 个答案:

没有答案
相关问题