0

I have the following sample code for a class library. after compiling I get no errors and everything seems fine but once I try to use it I get Error: Activex component can't create object: 'K32HardLinkWrap.Class1'

Imports System.Runtime.InteropServices

    Public Class Class1
        <DllImport("Kernel32.dll", CharSet:=CharSet.Unicode)>
        Private Shared Function CreateHardLink(ByVal lpFileName As String, ByVal lpExistingFileName                 
              As String, ByVal lpSecurityAttributes As IntPtr) As Boolean
        End Function
        Public Shared Function CreateHardLink_Api(ByVal lpFileName As String, ByVal lpExistingFileName As String, ByVal lpSecurityAttributes As IntPtr) As Boolean
            CreateHardLink_Api = CreateHardLink(lpFileName, lpExistingFileName, lpSecurityAttributes)
        End Function
    End Class

Here is when I get Error: (This is a VB script File)

Set objAPI = CreateObject("K32HardLinkWrap.Class1")

I have tried many things I found searching SE but none of them works for me so I suppose I have something really wrong in the code and not in the registration process or while building the dll.

Things I tried:

using both regsvr32 from system32 and syswow64

using both cscript from system32 and syswow64

Using regasm both 32 and 64 versions

Register For COM Interop

Made Assembly COM VISIBLE.

I am not moving the dll file to system32 I am keeeping it in same dir as script in case this makes a difference, since I dont want to pollute my system directory with test dlls.

* UPDATE * This was just me being dumb and not correctly specifying the correct cscript (32) to run. Now I still have another problem Apparently I am not exposing CreateHardLink_Api correctly since i get a Object doesn't support this property or method" error.

arana
  • 129
  • 11
  • I don't use VB.Net. If I was guessing, first thing I would try is using the ComVisible(true) attribute on the Class1 class. Build, and then use regasm /tlb /codebase with your DLL name to register it. I'd also look into the registry to see if I could find the ProgId K32HardLinkWrap.Class1 entry. Then if I found it, I would look up its CLSID, and from the CLSID see if I could find the InProcServer32. Personally, I would use the Guid and ProgId attributes on the class to hard code them. You do not want your Guid changing from compile to compile which it used to do years ago. (and may still?) – Joseph Willcoxson Feb 24 '20 at 22:01
  • I tried all of those except for searching the registry, following your advice I see there is no corresponding CLSID in HKCR\CLSID (INPROCSERVER32), but the class is registered in HKLM\SOFTWARE\Classes, so what to do next? – arana Feb 24 '20 at 22:15
  • Also, check out this [COM DLL Checklist](https://stackoverflow.com/a/35985827/692942). – user692942 Feb 25 '20 at 07:53
  • 2
    Get rid of "Shared" on CreateHardLink_Api. it's the VB equivalent of a static method and you can't expose those to COM. – Joseph Willcoxson Feb 25 '20 at 15:02
  • Ok one step further, now I get "Class doesn't support automation". So now I can properly call it, but still have something wrong in the code. – arana Feb 25 '20 at 17:39
  • not duplicate, since the other thread is creating the library in c#, this is not the case in this case librry is being created in VB.net, also the way to fix had nothing to do with the other solution provided. dont the mods at least read the questions or just the titles? – arana Feb 26 '20 at 00:54

0 Answers0