0

I need to use a DLL created in C in a C # application. I have followed several ways seen on the internet and I can not use the methods that are supposed to be in the DLL. When looking for the entrypoints I get 4, which are the following.

  • DllCanUnloadNow
  • llGetClassObject
  • DllRegisterServer
  • DllUnregisterServer

I'm trying with the following code:

[DllImport("DLL.dll", EntryPoint ="DllCanUnloadNow" ,CharSet = CharSet.Auto)]
    public static extern int Open();

    static void Main(string[] args)
    {
        Console.WriteLine(Open());
        Console.ReadLine();
    }

It doesn't matter what function I use, it returns always 0. If I use a function called for example, asdf() I got 0.

Does anyone know how to use the DLL correctly? I think it's made as COM and I have a .lib file.

Thanks in advance.

ernes3
  • 101
  • 1
  • 1
  • 15
  • 2
    Yes, your are right. DllGetClassObject, DllRegisterServer, DllUnregisterServer are indicative of an DLL providing COM objects/interfaces. Look up how you can interact with COM in C#/.NET (2 links: https://stackoverflow.com/questions/635839/best-way-to-access-com-objects-from-c-sharp, https://msdn.microsoft.com/en-us/library/ms973800.aspx). With regard to how and what to do with the specific COM interfaces offered by this DLL, you would need the documentation provided by the developer/vendor of this DLL... –  Mar 13 '18 at 17:14
  • I tried adding a reference, but when I select the .dll or the .lib, i got the message: A reference to: 'path\DLL.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM Component. I have a doc with the methods btw. – ernes3 Mar 13 '18 at 17:30
  • You need a `.tlb` compiled COM type library file. Contact the vendor of the COM dll if you don't have one. – Mark Benningfield Mar 13 '18 at 17:37
  • It is a COM server. Use Project > Add Reference > Browse button to use it. The owner of the component can provide you with a programming guide. – Hans Passant Mar 13 '18 at 17:39
  • Hello Mark. I have a .tlb file. How can I use it? – ernes3 Mar 13 '18 at 17:47
  • By reading the MSDN link that @elgonzo provided. A tutorial on COM interop is too broad for Stack Overflow. The information is widely available on the Web. – Mark Benningfield Mar 13 '18 at 17:57

0 Answers0