Does a COM DLL have to be compiled and registered for each bit edition? - dll

Is it OK for a COM DLL to be compiled as AnyCPU and work with both 32 bit and 64 bit applications?
Yesterday I started writing a C# COM DLL so that my MFC project could use the DLL. The DLL itself is for using the GMail API.
Initially I was compiling the DLL as either x86 or x64 and both of my executables were running fine.
Then I decided to change the DLL to compile as AnyCPU and now when my program runs it says Class not registered.
Does the DLL have to be compiled for each Bit edition then?

No, you can keep the .DLL compiled as "Any CPU" (in fact I certainly recommend it as long as you can), but you must register it in each version of the registry, so for example using regasm:
64-bit:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe ClassLibrary1.dll /codebase /tlb
32-bit:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe ClassLibrary1.dll /codebase /tlb

Related

DLLs won't register under 32-bit or 64-bit. How do I register them?

I've copied my dlls into both C:\windows\System32 and C:\windows\SysWoW64, and have executed regsvr32.exe into both of them, and have ended up with an error message telling me that name.dll may be incompatible and that I should try registering under the other folder.
Side note: I am running cmd as an administrator. I have Windows 7, 64-bit OS.
Edit: Also, I have confirmed that the dlls are 32-bit.
Is your DLL a COM DLL
The Regsvr32 Tool (regsvr32.exe) is used to register or un–register a COM DLL.
Regsvr32

32 bit DLL within WOW64

I've read about running 32 bit DLLs in 64 bit environments, especially here. But I'm still getting errors. Here's what I have. I have a real old 32-bit DLL that can't be converted to 64 bit. I have another DLL, my own, written in VB.NET, that I've compiled as x86. It calls the older one. My DLL is part of a Windows Service which I've compiled to x86 as well. So all x86 running on a 64-bit Win2012 server. The older DLL is actually installed on the machine itself, not part of my DLL or the Win Svc because of the nature of that DLL.
The older DLL is invoked using the standard X = CreateObject("oldDLL"). Everything works until I try to call a method on X. Then the method can't be found.
Any thoughts?

Statically compile SQLite into a VB.Net application?

System.Data.SQLite (SDS) is apparently the most popular way to use SQLite from a .Net application.
I was wondering if
SDS requires shipping the SQLite DLL in addition, or if SDS includes
the SQLite source code, and
SDS can be statically compiled into a
VB.Net application of it can only be shipped as a DLL?
Thank you.
To expand on my comment, SDS is a .net wrapper for unmanaged code, so you will need to ship your release code with a copy of the DLL.
As Steve mentions, there are 32 and 64bit versions of the DLL, and as i discovered after much frustration, you must have the corresponding visual c++ runtime installed on the target machine, so if you deploy the 32bit version onto a 64bit machine, it will need the 32bit c++ runtime environment installed.
An alternative that i am currently looking into but havent had time to test is csharpe-sqlite, a pure .net implementation:
http://code.google.com/p/csharp-sqlite/
Coded in c# as the name suggests, but of course usable in any .net language including vb.net
Actually it's quite easy to compile System.Data.SQLite.dll to the does not require C++ runtime. For example if you download source code and follow the build procedures you'll find statically linked (no C/C++ runtime required) copy of System.Data.SQLite.dll in the following path:
<your-src-root>\bin\<2008 or 2010>\<Win32 or x64>\ReleaseStatic
For example if your source is in C:\Work\sqlite-netFx-source-1.0.80.0 then statically linked binary for Win32 and .NET 3.5 (VS 2008) will be located in:
C:\Work\sqlite-netFx-source-1.0.80.0\bin\2008\Win32\ReleaseStatic
Furthermore since System.Data.SQLite.dll is a mixed-mode assembly consisting of a managed .netmodule and native .obj file linked together using link.exe, it is possible to build your app as a .netmodule as well and link it together with SQLite into a single mixed mode assembly.
The resulting assembly will still be either Win32 or x64, however since almost all x64 machines will have no problem running Win32 code you can just settle on Win32 as long as:
Your app is an .exe or a .dll the is always loaded into a Win32 process, and
You don't use any of x64 specific advantages such as larger address space or using unmanaged code available only in x64

Visual Studio 2010 64-bit COM Interop Issue

I am trying to add a VC6 COM DLL to our VS2010RC C# solution. The DLL was compiled with the VC6 tools to create an x86 version and was compiled with the VC7 Cross-platform tools to generate a VC7 DLL.
The x86 version of the assembly works fine as long as the consuming C# project's platform is set to x86. It doesn't matter whether the x64 or the x86 version of the DLL is actually registered. It works with both. If the platform is set to 'Any CPU' I receive a BadImageFormatException on the load of the Interop.<name>.dll.
As for the x64 version, I cannot even get the project to build. I receive the tlbimp error:
TlbImp : error TI0000: A single valid machine type compatible with the
input type library must be specified.
Has anyone seen this issue?
EDIT:
I've done a lot more digging into this issue and think this may be a Visual Studio bug. I have a clean solution. I bring in my COM assembly with language agnostic 'Any CPU' selected. The process architecture of the resulting Interop DLL is x86 rather than MSIL.
May have to make the Interop by hand for now to get this to work.
If anyone has another suggestion let me know.
This issue can be resolved by opening the CSProj file and adding the following node to any of the '(Configuration)|Any CPU' nodes that are missing it:
<PlatformTarget>AnyCPU</PlatformTarget>
If this node is not present TlbImp will default to x86 and cause issues.

C# COM DLL: do I use Regasm, or Regsvr32?

I am building a C# ActiveX DLL... do I use REGASM or REGSVR32 to register it?
How do I register the 64-bit interface vs the 32-bit interface?
You need to use regasm.exe to register both the 32 bit and 64 bit interfaces I believe you need to run each of the regasm.exe's in:
C:\Windows\Microsoft.NET\Framework\v2.0.50727
and
C:\Windows\Microsoft.NET\Framework64\v2.0.50727
So... in your case you need to run the regasm.exe in the Framework64\v2.0.50727 folder.
Here's an example we use to register a COM interop DLL for one of our legacy ASP apps:
regasm.exe Hosting.DeviceManager.Power.dll /register /codebase /tlb
If the DLL is build in format of "Any CPU", no matter if you choose regasm in
C:\Windows\Microsoft.NET\Framework\v2.0.50727
or
C:\Windows\Microsoft.NET\Framework64\v2.0.50727
DLL would be registered as 32-bit.