none
32 bit/ 64 bit .Net/COM interop - need an advice RRS feed

  • Question

  • I need to develop a plugin for old 3rd parth 32bit program.

    The plugin is basically implementing an interface with two functions.

    Mostly it's a simple task already completed, but there is one problem:

    One of the parameters of the interface function is a pointer to IDispatch interface object.

    I created marshaling rule and it works fine on 32 bit system, however with 64 bit system I have a problem:

    - Since the pointer is 32bit in the old application, that's what is sends, while my plugin is AnyCPU which results in the fact that on 64 bit system it's 64 bit pointers.

    Of course I can pass it as Int32 but then I am unable to "cast" it to the interface object. (And I do need to du such since I have to call functions on this interface pointer)

    Making my plugin x86 is not an option since this assembly is part of the complex project structure and it uses other assemblies that need to be AnyCPU since they participate in other projects.

    So I am a bit out of ideas righ now.

    Any suggestions/tips?

    Thank you in advance.

    Wednesday, August 8, 2012 9:27 PM

Answers

  • What is the "plugin" ?

    Is it a dotnet class library DLL?

    If it is a dotnet  DLL, you may consider in wrong way.

    I just discuss in the case of a Dotnet AnyCPU class Library DLL. If your plugin is another thing, it does not apply.

    Running in 32/64 bit of a general Dotnet(2 or above) AnyCPU class Library DLL is not just simplely based on 32/64 bit OS, but also the main application which is 32/64 bit.

    If the calling app is a 32bit app which loads the .NET anycpu DLL, even the OS is 64 bit, the DLL is running in 32 bit. It should be your case, so that it will not have any problem.

    If the calling app is a 64bit app which loads the .NET anycpu DLL in a 64 bit OS, the DLL is running in 64 bit.

    Thursday, August 9, 2012 1:31 AM

All replies

  • What is the "plugin" ?

    Is it a dotnet class library DLL?

    If it is a dotnet  DLL, you may consider in wrong way.

    I just discuss in the case of a Dotnet AnyCPU class Library DLL. If your plugin is another thing, it does not apply.

    Running in 32/64 bit of a general Dotnet(2 or above) AnyCPU class Library DLL is not just simplely based on 32/64 bit OS, but also the main application which is 32/64 bit.

    If the calling app is a 32bit app which loads the .NET anycpu DLL, even the OS is 64 bit, the DLL is running in 32 bit. It should be your case, so that it will not have any problem.

    If the calling app is a 64bit app which loads the .NET anycpu DLL in a 64 bit OS, the DLL is running in 64 bit.

    Thursday, August 9, 2012 1:31 AM
  • Thank you , you are correct, I just tried to output size of IntPtr from the plugin and it indeed runs in 32 bit.

    My problem lies elsewhere (casrting the recieved object to XSXML.IXMLDocument2 )

    You made my day !

    Thursday, August 9, 2012 9:27 AM