How to use method from VB6 dll in .NET? - c#

I have ActiveX VB6 DLL (have no access to its sources), and want to call method 'GetUnitInfo'
I use to import it like:
[DllImport(#"C:\Users\R\Documents\lab.dll")]
public static extern long GetUnitInfo(String strRequest, String strInfo, String strName);
But I get an exception:
Unable to find an entry point named 'GetUnitInfo' in DLL
Also I have tryied to load it:
Assembly myAssembly ;
myAssembly = Assembly.LoadFile("C:\\Users\\R\\Documents\\lab.dll");
but getting an exception
The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
I have tryied to clean solution, to turn off manifest in project options, to create new manifest file, but it did not helped me...

Found solution, mb someone else will find useful, (this worked in my case):
Create .Net wrapper of VB6 ActiveX dll
1.1 Run CMD as Administrator
1.2 Move to .NET SDK folder - cd C:\Program Files\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\ (in my case).
1.3 Run - TlbImp.exe C:\path_to_old.dll /out: new.dll
Register ActiveX dll
2.1 Run CMD as Administrator
2.2 Run - regsvr32.exe C:\path_to_old.dll
Add Reference to converted dll ("new.dll") in c# project
I used to add "new.dll" reference before registering "old.dll", and was getting the following exception
Retrieving the COM class factory for component with CLSID {F2D4F4E5-EEA1-46FF-A83B-A270C92DAE4B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Cleaning solution, removing reference and following steps 2,3 - helped
You may also find useful this articles
C-Sharp-and-activex-dll
Error adding reference to dll: Solution tlbimp.exe

Related

Retrieving the COM class factory for components with CLSID - Class not registered

I am trying to run my Windows Application (winForm) on a PC (OS Win7, 64 Bit) but it showing me this error or exception:
Retrieving the COM class factory for components with CLSID
{00853A19-BD51-419B-9269-2DABE57EB61f} failed due to the following
error: 80040154 Class not registered (Exception from HRESULT:
0x80040154 (REGDB_E_CLASSNOTREG)).
I google and found that I should need to Build for x86 (Althought current window is 64 bit). I did this but getting the same error. After that now I trying to install zkeeper dependency but getting this error:
The Module D:\TheSDK\zkemkeeper.dll" may not compatible with the
version of windows that you are running. Check if the moduel is
compatible with an x86 or x64 version of regsvr32.exe
Here is batch file (Dependency SDK installer) :
cd /d %~dp0
if /i "%PROCESSOR_IDENTIFIER:~0,3%"=="X86" (
echo system is x86
copy .\*.dll %windir%\system32\
regsvr32 %windir%\system32\zkemkeeper.dll
) else (
echo system is x64
copy .\*.dll %windir%\SysWOW64\
regsvr32 %windir%\SysWOW64\zkemkeeper.dll
)
Update: Even I try to run and install manually both regsvr of system32 and 64 and still getting same error.
I don't know what was the problem but maybe it was related to .Net framework. After installing the developer pack of .Net Framework 4.5.2. I deleted my SDK and register all the dependency (DLL) again. Then, it worked.
This error occurs because the com dll Zmkeeper.dll was not able to register. In some cases, it might need to be registered along with a typeLib file. Also, there could perhaps be some custom installer action performed if it goes through an installer. Seems like a demo version installation solved the problem. checkout this issue mentioned here

C# error: Unable to load DLL 'AutoItX3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

DLL is available inside 'References'.
I can able to run the test using 'Test Explorer' successfully
Problem:
Same test when im running from mstest commands- im getting the following error,
error: Unable to load DLL 'AutoItX3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Where i'm wrong ? can anyone show me the way for resolving this issue!
Thanks for your help
This seems to be late, but if you still need an answer, here is my way: Change platform target of your project.
In visual studio, right click project -> Properties -> Build > Platform target -> Try to change x86 or x64.
platform target
Do one thing
register your AutoItX3.dll:
Bu opening the CMD in Administration and execute the below command, change the path of according to your location
regsvr32 "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll"
you will get a message box telling you it was successful.
Now try to run the test

EmguCV: Unable to load DLL 'cvextern': The specified procedure could not be found

When publishing project to windows server 2003 (old test machine) I get following error when trying to call open cv functions.
Additional information: The type initializer for 'Emgu.CV.CvInvoke' threw an exception.Unable to load DLL 'cvextern': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
I am using EmguCV 3.4.1 version with uploaded libraries:
vcruntime140.dll
opencv_ffmpeg341.dll
msvcp140.dll
cvextern.dll
concrt140.dll
To the Emgu package nothing extra (dll's) were added and on developer machine I could develop the application.
I keep wondering whether additional native dll's should be added. I downloaded binaries for 3.4.1 version. The files go like that:
opencv_core249.dll
opencv_highgui249.dll
Those two above where in 3.4.1 package. When i copied them to program directory it didn't help either.
What's more I have no idea how to track down the problem.
Process monitor doesn't show that the process is looking for something that cannot be loaded.
In the inner exception I am given only this exception: Unable to load DLL 'cvextern': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
I had to install "Desktop Experience" feature on my server. Because server 2003 doesn't seem to have it, I had to move it to another server 2008 host.

Cannot load a Strong name assembly by Assembly.LoadFrom(), call fails with 0x80004005 (E_FAIL)

I have an Adobe acrobat plugin that uses System.Reflection.Assembly.LoadFile(path) in an AssemblyResolve event that will fail anytime I try to load a signed assembly. The error is
The assembly with display name 'Microsoft.AspNet.SignalR.Client' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
I have to use AssemblyResolve event because the needed assemblies will live in a folder a couple levels beneath Acrobat's exe. Here is the code that AssebmlyResolve calls.
Assembly^ TeamMateIntegrationManagedWrapper::ResolveAssembly(Object^ sender, ResolveEventArgs^ args){
try
{
// This method will be called if an assembly cannot be found.
// The assembly should be 2 folders below the current working directory where the Adobe Acrobat executable lives.
AppDomain^ appDomain = static_cast<AppDomain^>(sender);
String^ path = appDomain->BaseDirectory;
path += "plug_ins\\MyAppName\\" + args->Name->Split(',')[0] + ".dll";
return System::Reflection::Assembly::LoadFile(path);
}
catch (Exception^ ex)
{
String^ msg = ex->Message;
}
return nullptr;}
The Acrobat plugin is in mostly C but has a CLI bridge class to wrap the managed C# Assembly that uses SignalR.
Things I've tried.
Put all the necessary dll's in the same folder as Acrobat's executable to get around using the AssemblyResolve event.
Verified the SignalR version and PublicKeyToken of the dll that I'm providing in the AssemblyResolve event matches exactly what is being requested in the ResolveEventArgs
Verified that all my assemblies (including plugin dll) are targeting .Net Framework v4.6 and the plugin dll is building for x86 and other assemblies are build for Any CPU.
Tried Assembly::LoadFrom(path) instead of LoadFile(path), same error loading assembly.
Rebuilt SignalR from the source code and removed the Strong Name, the SignalR assembly loaded successfully in the AssebmlyResolve event. Added the strong name back to the SignalR assembly and got the above error again.
Added Strong name to my C# assembly, got the same error as above just like SignalR assembly.
Looked at fusion log viewer but nothing was logged for Acrobat.
Created a C++ console application that contains the same CLI bridge wrapper class that uses the same C# assembly that consumes SignalR, same error as above. Looked at fusion logs but no log for Microsoft.AspNet.SignalR.dll under my ConsoleApplication.exe folder. Looked at fusino log for my C# assembly that uses SignalR and there is not any reference/mention of SignalR dll trying to load in the log file.
Adobe Reader has an option/preference Edit->Preferences->Security (Enhanced)->Enable Protected Mode at startup that launches the application in a protected sandbox. This protection was preventing the Strong named dll from being loaded.

Unable to load DLL VistaDb20.dll because of an invalid access to memory location (HRESULT: 0x800703E6)

I have a project that was built in Visual Studio 2005 in C#. I created an installer for the Windows application (in VS2010) and it installs and works fine on Windows XP SP3. I tried installing it on Windows 7 32-bit and it says installation is successful but when I try to open the application I receive this error message:
A fatal error has occurred. Unable to load DLL 'VistaDb20.dll': Invalid
access to memory location. (Exception from HRESULT: 0x800703E6)
People suggested I run this in the command line:
regsvr32 VistaDb20.dll
I get the error message:
The module "VistaDb20.dll" was loaded but the
entry-point DllRegisterServer was not found.
Make sure that "VistaDb20.dll" is a valid DLL or OCX
file and then try again.
So then I tried regasm VistaDb20.dll /tlb:VistaDb20.tlb using the .NET Framework Assembly Registration Utility 2.0.50727.4927 and get error:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I am not sure how to get my application running on Windows 7 with this .dll problem. Any help would be appreciated. This application and the database was created using VistaDB 2.1
I guess I can't change the actual dll since I did not create it but maybe I have to change some properties of the dll in Visual Studio?
I had this error while trying to registering my VB .NET assembly using RegAsm command:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I solved the problem buy executing RegAsm of the right .NET Framework.
I mean you should use the tools of the same Framework that you make as target in your advanced options of compilation (VS2010).
According to this your problem is that this DLL is not compatible with DEP. You'll need to disable DEP to workaround this but in the long term you should try to wean yourself off this particular dependency.

Categories

Resources