Pergunta

Sorry for the confusing title,

I'm using c# and trying to work with ArcMap which is bunch of dlls that allows me to work with geographical files and writen in c++ and then wrapped in managed c++, the Arcmap version that I have at my work place is 32bit, so the only way to interact with its Dlls is by developing 32bit application.

I have a 64 bit application, that uses a class that I wrote that is located in another dll (which i can make 32bit or configure in any way necessary) , the class loads ArcMap dlls and trying to use them to read some file (shape file)..

The problem is that i can't load 32bit class from 64bit application... And i can't change the class that uses the Arcmap objects from 32 bit to 64 bit because then the arcmap dlls won't load.

The only solution i currently have is to convert the class to a console project, run it as 32bit and wait for it to finish, the console project will write the data he red into txt file which in turn i'll read from my original 64bit application.

That is the ugliest workaround i ever had, i hope that someone can help me find a better solution.

Thanks in advance,

P.S If some part in my question is unclear please comment what and i'll try to explain what i meant.

Foi útil?

Solução

You have the following constraints:

  • You cannot execute 32 bit and 64 bit code in the same process.
  • The third party code is supplied in binary form, as 32 bit modules.

From this you can conclude that the third party code must run in a 32 bit process. This means you have the following options:

  1. Convert your process to 32 bit if that is possible. This is far and away the easiest solution.
  2. Leave your process as 64 bit, and run the third party code as a separate process.

The ugly solution you describe in the question is one way to implement option 2. But there are less ugly ways to do that. Instead of communicating using external files, you can use a remote procedure call mechanism (RPC).

There are plenty of options but the most obvious one is COM. Put the 32 bit code into an out-of-process COM server and consume it from your 64 bit application. This will let you write clean code that communicates to the third party library using method calls. The underlying RPC mechanism does all the low-level heavy lifting involved with getting information between the two processes.

Outras dicas

You can as well create a 32bit application and enable COM/DCOM or other kind of .NET remoting to discuss with your main application that is 64 bit. So you do not need to read/write files. You can also resort to other forms of IPC (named pipes, DCE/RPC) - but this might be not as straightforward.

See here some pointers:

Is there a viable counterpart to DCOM in .NET?

DCOM server and client both written in .NET

How can a 32 bit process communicate with a 64 bit process in .NET?

You can convert the 64bit application into 32bit application through the following syntax: CorFlags.exe xxx.exe /32BIT+

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top