Mr. Smith
Mr. Smith

Reputation: 4506

Using a 64bit DLL in a 32bit Application

XCode's ARC refactoring forced my Cocoa Library DLL to be 64bit, and I don't know if I can still DllImport that DLL from an x86 C# application. Is this possible, and are there any consequences of doing so?

Upvotes: 6

Views: 13114

Answers (3)

Joshua
Joshua

Reputation: 43188

The solution when necessary is to call an EXE in pipeline or similar. This assumes of course a 64 bit windows. If not, punt.

Upvotes: 0

Roman Gruber
Roman Gruber

Reputation: 1411

The problem is not really C# - it is the hosting process in the OS. Since one process can only load DLLs with the same "bitness", either the process is 64bit or you cannot directly load your DLL. No matter what language or framework you are using.

One solution would be to target the C# project to use "any" cpu or specifically point it to X64.

Another solution would be to create a hosting process that you can communicate with using IPC or similar models.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 612784

You cannot mix 32 bit and 64 bit code in a single process. So the only way to use mix bitness code is to have more than one process. You'll need some form of IPC to make it work. You cannot do it with DllImport since that is in-process.

Upvotes: 8

Related Questions