0

サード パーティの .NET dll をネイティブ C++ dll に公開したいので、C# でラッパー dll を作成しました。しかし、ネイティブ C++ dll では、CoCreateInstance() を実行するたびに、この -858993460 エラーが返されます。

----------------------プログラムの構成は以下の通りです-----------------

ThorDetectorSwitch.dll(ネイティブ C++ dll) -> MCLWrapper.dll(COM C# dll) -> mcl_RF_Switch_Controller64.dll(サード パート .NET dll)

----------------------以下は私のコードの一部です---------------------- -

C# ラッパー dll (MCLWrapper.dll、COM 呼び出し可能ラッパー dll):

// C# COM wrapper for mcl_RF_Switch_Controller64.dll 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mcl_RF_Switch_Controller64;
using System.Runtime.InteropServices;
// for function reference see miniCircuit RF controller manual

namespace MCLWrapper
{
    [Guid("727C569D-09AF-472c-8032-2AC9BC7CDC30")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComVisible(true)]
    public interface MCLControl
    {
        [DispId(1)]
        void Connect(string SerialNumber);

        [DispId(2)]
        void Set_Switch(string SwitchName, int Val);

        [DispId(3)]
        void Set_SwitchesPort(byte binVal);

        [DispId(4)]
        void GetSwitchesStatus(int statusRet);

        [DispId(5)]
        void Disconnect();
    };

    [Guid("68A7F8A1-6347-4bb1-9809-EE18E1E9BDD6")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("MCLWrapper.MCLControlClass")]
    public class MCLControlClass : MCLControl
    {
        public USB_RF_SwitchBox _sb = new USB_RF_SwitchBox();

        //public MCLControlClass() { }    
        public void Connect(string SerialNumber)
        {
            _sb.Connect(ref SerialNumber);
        }

        public void Set_Switch(string SwitchName, int Val)
        {
            _sb.Set_Switch(ref SwitchName, ref Val);
        }

        public void Set_SwitchesPort(byte binVal)
        {
            _sb.Set_SwitchesPort(ref binVal);
        }

        public void GetSwitchesStatus(int statusRet)
        {
            _sb.GetSwitchesStatus(ref statusRet);
        }

        public void Disconnect()
        {
            _sb.Disconnect();
        }
    }
}

ThorDetctorSwitch.dll のコンストラクタ (CCW MCLWrapper.dll を呼び出すネイティブ C++):

#import "../MCLWrapper/MCLWrapper/bin/Debug/MCLWrapper.tlb" raw_interfaces_only

using namespace MCLWrapper;

MCLWrapper::MCLControl *_mcSwitch;

ThorDetectorSwitch::ThorDetectorSwitch()
{
    HRESULT hr = CoInitialize(NULL);
    MCLWrapper::MCLControlPtr mclSmartPtr;
    hr = ::CoCreateInstance(__uuidof(MCLWrapper::MCLControlClass), NULL,CLSCTX_ALL, __uuidof(MCLWrapper::MCLControl), (void**)&mclSmartPtr    );
    _mcSwitch = mclSmartPtr;

    _A  = WstringToBSTR(L"A"); 
    _B  = WstringToBSTR(L"B");
    _C  = WstringToBSTR(L"C");
    _D  = WstringToBSTR(L"D");

    _deviceDetected = FALSE;
}

MCLWrapper.dll の登録に使用したコマンド ライン

regasm MCLWrapper.dll /tlb:MCLWrapper.tlb /codebase

レジストリを正常に返します。

エラー: エラーは次の場所で発生します

hr = ::CoCreateInstance(__uuidof(MCLWrapper::MCLControlClass), NULL,CLSCTX_ALL, __uuidof(MCLWrapper::MCLControl), (void**)&mclSmartPtr    );

そして、この線が完全に実行されたとは思いません。

誰でも何か考えがありますか?どうもありがとう。

4

0 に答える 0