Click here to Skip to main content
15,887,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a third party .NET dll which I want to expose to a native C++ dll, so I wrote a wrapper dll in C#; But in the native C++ dll, every time when it excutes to CoCreateInstance(), it returns this -858993460 erroe;

----------------------Below is the structure of the program-----------------

ThorDetectorSwitch.dll(native C++ dll) -> MCLWrapper.dll(COM C# dll) -> mcl_RF_Switch_Controller64.dll(third part .NET dll)

----------------------Below is some o my code-----------------------

The C# wrapper dll (MCLWrapper.dll, COM callable wrapper dll):

C#
// 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();
        }
    }
}


The constructor of ThorDetctorSwitch.dll (The native C++ that calls the 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;
}


The command line I used to register MCLWrapper.dll

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


and it returns registry successfully.

Error:
The error occurs at

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


and I don't think this line is completely excuted.

Anyone has any idea? Thanks a lot.
Posted
Comments
Richard MacCutchan 17-Jun-13 12:49pm    
That does not translate to a valid error code (FFFFFFFFCCCCCCCC hex). Print the value in hex to check it.
David Pickering 19-Sep-13 11:04am    
0xcccccccc is the value the runtime assigns to uninitialised variables iirc
YvesDaoust 17-Jun-13 15:14pm    
How exactly do you check the returned value ? This looks like an uninitialized value and I doubt this is the true returned value.
Matthew Faithfull 17-Jun-13 16:57pm    
Are you sure you want CLSCTX_ALL and that it matches the class object registration?

1 solution

Remove the CoCreateInstance() out of the constructor will solve the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900