Search code examples
c++dllcom

using com dll from unmanaged c++ fails with REGDB_E_CLASSNOTREG


I'm really stuck with this and after spending hours of time with google and such I need to ask here because I'm out of ideas...

Using this example I currently have this:

#include <stdio.h>
#include <tchar.h>
// get ATL's client templates
#include <atlcomcli.h>
// import the typelibrary direct from the dll
#import "FibuSvrDLL.dll" raw_interfaces_only no_namespace

int main(int argc, char* argv[])
{
    // declare com ptr
    CComPtr<_Server> comInterfacePtr;

    // cocreate an instance
    HRESULT r = comInterfacePtr.CoCreateInstance(__uuidof(Server));
    // this always fails with REGDB_E_CLASSNOTREG
}

_Server seems to be the right interface and Server is its coclass. See here the corresponding snippet from generated tlh File:

struct __declspec(uuid("5f3a9f5c-196d-4e4c-b339-6664c1c7f4f9"))
/* dual interface */ _Server;
struct /* coclass */ Server;

If I use the same DLL from within c# it works out of the box:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using fnSrvDLL5r;

namespace ConsoleApplication1
{
    class Program
    {
        public Program()
        {
            try {
                Server server = new Server();
                server.set_Konfiguration("...");
                [...]

The DLL is part of a 3rd party application I've no control of. All I know is that it's written in VB6.

Before I was able to use the DLL from within above c# code I need to use regsvr32 at first. Maybe this is of any help.

Regards, Martin


Solution

  • Your code as shown doesn't call CoInitialize() or OleInitialize(). You will never succeed without calling those first.