程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> java-jacob c++裡方法的類型是bstr ,為啥JAVA調用時老是出錯

java-jacob c++裡方法的類型是bstr ,為啥JAVA調用時老是出錯

編輯:編程綜合問答
jacob c++裡方法的類型是bstr ,為啥JAVA調用時老是出錯

[id(4)] HRESULT sayHello2([in] BSTR say, [out, retval] BSTR* result);

ComThread.InitMTA(true);
ActiveXComponent com = new ActiveXComponent("CLSID:FF90EFCA-0856-4159-A9CC-0E7BBC317554") ;

  Dispatch disp = (Dispatch) com.getObject();
  Variant  a = new Variant(11);
  Variant  b = new Variant(2);
  Variant c  =  new Variant();

  c = Dispatch.call(disp, "Add",2,3);
  System.out.println(c.toString());
  Variant v = Dispatch.call(disp, "sayHello2","fuck");

  System.out.println(v.toString());
     Can't map name to dispid: sayHello2

最佳回答:


ComThread.InitMTA(true);
ActiveXComponent com = new ActiveXComponent("CLSID:FF90EFCA-0856-4159-A9CC-0E7BBC317554") ;

  Dispatch disp = (Dispatch) com.getObject();
  Variant  a = new Variant(11);
  Variant  b = new Variant(2);
  Variant c  =  new Variant();

  c = Dispatch.call(disp, "Add",2,3);
  System.out.println(c.toString());



   //用新的字符編碼生成字符串
  try {
    byte[] bs = "fuck".getBytes();
    String xx = new String(bs, "UTF-8");
    Variant v = Dispatch.call(disp, "sayHello2",xx);
    System.out.println(v.toString());
} catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
 結果正確,
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved