2

The dll I am working with is called RGAComms.dll(It is unmanaged) According to my understanding of unmanaged dll, unless the function names are decorated all that should be available is the function names(not the actual signature). I have the following question about the below pictures.

  1. In the VS object browser after I added the dll to the program references, it displays the actual methods names plus the method signature. How could it possibly show the method signature.(My guess is that method names are decorated)

  2. This is my main question. When I run dumpbin on RGAComms.dll it only displays four method names that I believe have to do with Microsoft's COM.(See pic below) Why does it not display the actual method names in dll.(For example: "Connect" - This method can be seen in the VS object viewer of RGACommsLib)

  3. I know that this DLL DOES include the method "Connect".(As previously stated) When I execute the following code I get a exception that states that the entry point does not exist in the DLL. How could it not exist if one can clearly see it exists in the VS object viewer of the dll.(My guess is that because these method names are decorated the entry point will be something like "Connect@@@8" or something)

       [DllImport(@"PathOnMyLocalComputerToTheDll\RGAComms.dll")]
       public static extern void Connect(string strAddress);
    
          public MainMethod() {
             Connect("localhost");
          }
    

I almost sure all my questions probably boil down to one major misconception.

VS Object Browser Outputenter image description here

Dumpbin output:

Robo Maklen
  • 152
  • 1
  • 11
  • Yes, it is a COM server. It is DllGetClassObject() that gets the job done at runtime, that is that the [factory method](https://en.wikipedia.org/wiki/Factory_method_pattern) that creates objects. This server also includes a type library, embedded in the DLL as a resource, it is the exact equivalent of .NET metadata. Which is how VS knows what it does. Do not use pinvoke to use this DLL, simply use `var obj = new RGACommsLib.RGAConnection()` in your code to create the object and `obj.Connect(whatever)` to make the call. – Hans Passant Jun 20 '18 at 19:28
  • @HansPassant Oh I see! Could you put this in a answer form so I can make it the solution. This is my "major misconception". Thanks so much for the help! – Robo Maklen Jun 20 '18 at 19:47
  • Just share what you discovered in your own post, show a snippet of the code that works. The most likely way that anybody that uses this COM server will find the help he needs. – Hans Passant Jun 20 '18 at 19:51

2 Answers2

3

That DLL is in fact a in-processes COM server. Here is a great page about it: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683835(v=vs.85).aspx

The reason why only four methods are found from dumpbin are because it is a COM server. In this case all you have to do to use the classes from the DLL is the following code after you added the DLL to the references and set the embedded interop to false for that DLL.

    public RGACommsLib.RGAConnectionClass GA = new RGACommsLib.RGAConnectionClass();
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Robo Maklen
  • 152
  • 1
  • 11
1

While RGAComms.dll might be unmanaged, RGACommsLib.dll is managed and VS is showing you the classes and methods from that dll. I can see you have referenced this in your solution. Only managed dlls will show up in your references, not unmanaged.

Joel Lucsy
  • 8,520
  • 1
  • 29
  • 35
  • Only answers one of my questions(1.). So you saying VS basically did all the DllImport stuff for me? If so why cant I then just use the classes like objects(Like with a managed DDL)? When I try to do that I get the following error "Interloop class cannot be embedded. Use Interface equavalent". with the following piece of code: public RGACommsLib.RGAConnectionClass GA = new RGACommsLib.RGAConnectionClass(); I understand there is problems with classes across DLL's but I just want to access the methods. – Robo Maklen Jun 20 '18 at 18:14
  • VS will only generate assemblies for COM objects that you've explicitly picked, or was generated by someone else and you've referenced and added them yourself. There is no tool to bring in DllImport statements and generate classes for unmanaged dlls, as this is impossible. So the question in, how did those references get in there? Did you pick them from someplace, or pick a COM object? – Joel Lucsy Jun 20 '18 at 18:19
  • Since for a unknown reason the method names are not valid enter points with the actual DLL, is it possible I can use DllImport statement to reference the RGACommsLib to use the dll? – Robo Maklen Jun 20 '18 at 18:24
  • Without knowing how the two are related, I'm going to have to say no. – Joel Lucsy Jun 20 '18 at 18:26
  • Didnt see last part of your question. Step by step what I did was the following: 1. I used this in cmd: regsvr32 "filepathToDll" 2. I then clicked "add reference" in VS. 3. Then chose my dll. All I did, nothing else. – Robo Maklen Jun 20 '18 at 18:27
  • Ah, ok. Right, so its a COM assembly then. I looked for the error you said it reported and came up with this https://stackoverflow.com/questions/2483659/interop-type-cannot-be-embedded – Joel Lucsy Jun 20 '18 at 18:33
  • Lol I saw a couple of hours ago and it did not solve my problem. I tried it again and now it works! Thx! – Robo Maklen Jun 20 '18 at 18:53