Error calling 32 bit COM (C++) dll from C# console application from 64 bit machine

A

ashish

HI,


I have some question about using unmanaged 32 bit COM (C++) dll with
C# . We use Visual Studio 2005 to develop this C# dll on 64 bit
machine.


(1) When I call the C# dll built with ANY CPU option (which use the 32
bit COM (C++) dll) from C# console application (built with ANY CPU
option), it returns below error while I create new for 32 bit COM dll,

FYI, the ExOWAClient is C# dll where I add the reference for 32 bit
COM dll.



System.Runtime.InteropServices.COMException was unhandled

Message="Retrieving the COM class factory for component with CLSID
{5F56FA52-1A76-4776-B90A-24FF9030A1D4} failed due to the following
error: 80040154."

Source="ExOWAClient"

ErrorCode=-2147221164

StackTrace:

at ExOWAClient.ExRestoreShortcut.RestoreShortcutMessage(String
owaId, String emailAddress) in C:\Project2\ExOWAClient\ExOWAClient
\ExRestoreShortcut.cs:line 44

at TestOwaClient.Program.Main(String[] args) in C:
\Project2\OWAForm\TestOwaClient\TestOwaClient\Program.cs:line 12

at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)

at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

I try P/invoke but it does not work with COM dll either.
There is a work around by building whole application with 32 bit
option (CPU), and it works for my testing enviornment, but it is NOT a
real option for me.
I have to build application using Any CPU (means 64 bit) by calling 32
bit COM dll.
Also, I can not build my 32 bit COM dll with 64 bit either due to some
reson.

I really appreciate your response.
 
N

Nicholas Paldino [.NET/C# MVP]

ashish,

You can't do anything then. The 32-bit COM dll has to be recompiled for
a 64 bit platform in order to use it. The only other option you have is
hosting the 32-bit COM dll in another 32-bit process, and remote into the
process to call it. You could use remoting/WCF for this, or you might be
able to get away with using COM+ to handle the proxying.
 
W

Willy Denoyette [MVP]

ashish said:
HI,


I have some question about using unmanaged 32 bit COM (C++) dll with
C# . We use Visual Studio 2005 to develop this C# dll on 64 bit
machine.


(1) When I call the C# dll built with ANY CPU option (which use the 32
bit COM (C++) dll) from C# console application (built with ANY CPU
option), it returns below error while I create new for 32 bit COM dll,

FYI, the ExOWAClient is C# dll where I add the reference for 32 bit
COM dll.



System.Runtime.InteropServices.COMException was unhandled

Message="Retrieving the COM class factory for component with CLSID
{5F56FA52-1A76-4776-B90A-24FF9030A1D4} failed due to the following
error: 80040154."

Source="ExOWAClient"

ErrorCode=-2147221164

StackTrace:

at ExOWAClient.ExRestoreShortcut.RestoreShortcutMessage(String
owaId, String emailAddress) in C:\Project2\ExOWAClient\ExOWAClient
\ExRestoreShortcut.cs:line 44

at TestOwaClient.Program.Main(String[] args) in C:
\Project2\OWAForm\TestOwaClient\TestOwaClient\Program.cs:line 12

at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)

at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

I try P/invoke but it does not work with COM dll either.
There is a work around by building whole application with 32 bit
option (CPU), and it works for my testing enviornment, but it is NOT a
real option for me.
I have to build application using Any CPU (means 64 bit) by calling 32
bit COM dll.
Also, I can not build my 32 bit COM dll with 64 bit either due to some
reson.

I really appreciate your response.


Your only option is to build your managed application as 32 bit
(platform=x86), your COM dll is a 32 bit code COM server and probably has
dependencies on other 32 bit COM server dll's (OWA?). Both 64 bit and 32 bit
don't mix in the same process.
Another point is that unless you really need the addressable memory space
offered by 64 bit code, there is little or no reason to move to 64 bit,
really.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top