• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1784
  • Last Modified:

How can I run a 32 bit unmanaged dll from 64 bit C# app

I am not a C# programmer (I am more C++, Windows programming)...so my question has to do with the interface a 64 bit .net object uses to access a 32 bit unmanaged dll.  

I know that in order to access a 32 bit unmanaged dll from a 64 bit unmanaged application, an RPC mechanism, such as DCOM, can be used, where the data is transferred to a surrogate process by marshalling.

With regard to a managed application...can a .Net app use the same DCOM interface used by the unmanaged application, or is there some other mechanism that must be used?
0
monstro281
Asked:
monstro281
  • 7
  • 3
  • 2
  • +2
1 Solution
 
timexistCommented:
it will very a compilcate issue.
I faced a similar issue a while ago. a 32bit dll to open the cashdraw cannot work on x64 windows 7 machine.
It is too complicate to deal with it. There is no easy answer for this.
At last I found a simple solution .
I changed my project to target x86 cpu, it means everything go back to 32bit again, and x64 windows 7 is happy too.
So what I talking about here is that you can change your project to 32 bit to fit the out-of-date old 32bit dll.

0
 
monstro281Author Commented:
Yes...I am aware of this, but it is not an option for me.  On 64 bit platforms, the app will be 64 bit, but the dll's will remain 32 bit.  

Can the platform invoke method be used for RPC, or can .Net objects implement DCOM?
0
 
timexistCommented:
On 64-bit platforms, application can be 32bit, for windows just as default, it regard everything as 64 bit.
do you know CorFlags.exe? it can put a flag on the application, mark it as 32bit or not.
I solved another 64/32 issue, by using this tool only.
If you have to go com/dcom way, I have to say good luck and have fun.


0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
trinitrotolueneDirector - Software EngineeringCommented:
take a look at the code sample here.

http://software.intel.com/en-us/articles/access-a-32-bit-dll-from-a-native-64-bit-process-on-intel-architecture/

I'll get back with more stuff later today
0
 
monstro281Author Commented:
Too bad the download link is broken....it looked promising.
0
 
trinitrotolueneDirector - Software EngineeringCommented:
oh thats bad, I thought it didn't go thru since my conn was bad. i'll try to give u the same info.....i thought a link would be easier...
0
 
alexey_gusevCommented:
>> On 64 bit platforms, the app will be 64 bit, but the dll's will remain 32 bit.  

why is that? just change the target to x86 as it was suggested already and all will be fine. It worked perfectly well with managed/unmanaged code.
0
 
Corey ScheichDeveloperCommented:
I have used .Net remoting in the past to accomplish this.  You need a second process to instanciate an instance of the class then you remote to it.  I suggest creating a wrapper class that the x64 code will communicate with.

The gist of it is you create a class on one side of the fence then using remoting you get a pointer to that class then you make calls to it from the x64 process just like it was created there.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22071190.html?sfQueryTermInfo=1+net+remot
0
 
monstro281Author Commented:
alexey...as I said before, had you read my response, building in 32 bit is NOT and option.  It is a 3rd party application...and their guidelines restrict the app to be built with the "Any CPU" option.  I have to make it work with 32 bit dll's.  That is the bottom line.

0
 
monstro281Author Commented:
Corey2...does this solution work between managed and unmanaged code?
0
 
Corey ScheichDeveloperCommented:
You will have to create a x86 .Net exe that will create the 32bit object and expose it to x64.  The 32bit object can be managed or un-managed doesn't really matter.  Worst case you create a managed wrapper for the methods you need.  I would personally create a managed wrapper, matter of preference.
0
 
monstro281Author Commented:
Corey2...thanks for the input.  After researching this, it is possible to solve this problem using C# remoting.  The only problem with this approach is the complexity of exposing the x86 .Net exe (which hosts the 32 bit dll) to an unmanaged client.  It should be possible to communicate to the .Net host via COM...but I consider that more complex than simply using something like DCOM in an unmanaged client.

At this time, I am going to explore hosting the 32 bit dll in an unmanaged COM server.  I will expose the dll interface in a COM style wrapper implemented in the 64 bit .Net app, using DCOM to communicate with the COM server.  This will provide the easiest to implement, most general solution (in my humble opinion).  
0
 
monstro281Author Commented:
Corey2's response was a viable solution...but I am searching for an even more general solution.  Corey2's response lead me to the solution I was looking for...so he gets the A.
0
 
timexistCommented:
I am glad you can find something you are looking for.
Could please you explain what it is?
0
 
monstro281Author Commented:
timexist...the solution involves a remote procedure call type mechanism.  This can be accomplished by a few methods.  Corey2 suggested C# Remoting.  This is viable for the purpose I need, but is not the most general solution I could find.  It led me to conclude that the most general solution for managed/unmanaged code would be to use COM in an out of process server...distributed COM.  

Here is a link to a similar solution:

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/f2c10d58-ec35-4e7c-99dd-3d6c71c30112

Mike Becker also posted his own take a few years back:

http://www.dnjonline.com/article.aspx?id=jun07_access3264

The beauty of this solution is it can easily be used in both managed and unmanaged code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now