使用c++ builder 6 去用Import Type Library匯入C#撰寫的tlb檔(命令提示字元注冊DLL)
C#的部份有使用emgucv函式庫去執行一些圖片處理,C#則使用類別庫別撰寫COM組件,照著網上的教法去做基本處理運算
基本運算功能可正常在c++ builder 6 呼叫執行得到結果
但呼叫到emgu的部分就會有error的發生,想詢問有沒有前輩遇到類似問題,并且解決的
C# code
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Drawing;
using Emgu.CV; //Emgu
using Emgu.CV.Structure;
using System.Runtime.InteropServices;
namespace DectFunct
{
[Guid("6B4ED5B9-5356-42E3-A6CA-1A242F91583A")]
public interface IComInterface
{
//[DllExport("Dect", CallingConvention = CallingConvention.StdCall)]
[DispId(1)]
int Dect(int x_allspace, int y_allspace, int x_space, int dead_sum, int pic_name);
[DispId(2)]
string COMINFO { get; }
[DispId(3)]
int add(int x_allspace, int y_allspace);
}
[Guid("1A8EB38C-E732-49B2-A897-B40FFD744E3D")]
public class Class1 : IComInterface
{
public int Dect(int x_allspace, int y_allspace, int x_space, int dead_sum, int pic_name)
{
int result = 0;
float hexagon_L = x_space;
Image<Bgr, Byte> image_Source;
//String openFile = pic_name + ".png";
string name = Convert.ToString(pic_name);
String openFile = name + ".bmp";
image_Source = new Image<Bgr, byte>(openFile);
if (image_Source != null)
result = 1;
return result;
}
public string COMINFO
{
get
{
return "com 測試";
}
}
public int add(int x, int y)
{
int z = 0;
z = x + y;
return z;
}
}
#pragma hdrstop
#include <iostream>
#include <vcl.h>
#include "Dectfunct_tlb.h"
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
HRESULT hr;
//初始化COM
CoInitialize ( NULL );
Dectfunct_tlb::IComInterfacePtr ptr;
hr = ptr.CreateInstance(__uuidof (Dectfunct_tlb::Class1));
if(hr == S_OK)
{
cout << ptr->add (32, 16)<<endl;
cout << ptr->Dect (32, 16, 3, 1, 1)<<endl;
BSTR outp = NULL;
ptr->get_COMINFO(&outp);
cout<<AnsiString(outp)<<endl;
}
CoUninitialize ();
system("pause");
return 0;
}
由于一些C#撰寫COM元件,到c++ builder 6 的方法我就略過了,網上很多教學我就不多提
先附上我自己電腦的執行正確結果

可是在執行過后,我目前使用的電腦WIN7-64位元能正常編譯回傳值,但若把dll、tlb檔移至其他電腦使用,執行結果會出現

簡單的運算是可以過的,但使用到emgu的函式部分不確定是不是有系統上的問題還是哪邊有寫錯,這是我移植至其他電腦的執行結果

想詢問有沒有前輩有遇到這種error,并且有方法解決的,不確定是程式上的錯誤,還是軟體系統上的問題
uj5u.com熱心網友回復:
這部分的錯誤已經自行解決,在其他電腦系統需要安裝第三類類別庫元件以及設定路徑轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/64501.html
