How to use a 32bit DLL in Matlab 64bit

Hi, I need to interface two instrument to a matlab program. I have the 32 bit DLL of one of the instrument and the 64 bit DLL of the other. The 64 bit DLL comes with the precompiled mex and it seems to work well.
The problem is with the 32bit DLL that doesn't come with a precompiled mex. I know that this 32bit DLL has been created in VC++, I have an header file but not the source code. I tried to use the loadlibrary command but with no success (even on a 32bit version of Matlab).
I'm now searching for a workaround. My idea is to compile a VisualBasic 32bit EXE as a gateway between 64bit Matlab and 32bit DLL. Have you any idea of the smarter way I can "comunicate" withe EXE to execute some command on the instrument trough its DLL?
Thank you

Respuestas (2)

Walter Roberson
Walter Roberson el 7 de Jul. de 2017

1 voto

It is not possible to call between a 32 bit program and 64 bit DLL or the other way around.
You will need to do something like create a program that just calls the DLL and forwards the results to the other program, perhaps using tcp.

4 comentarios

Guillaume
Guillaume el 7 de Jul. de 2017
Note that this is not a matlab restriction. It is a Windows restriction. No 64 bit program is able to use 32-bit dlls directly.
This blog post describes the traditional way of interfacing with a 32 bit dll from 64 bit. The idea is to have a surrogate 32-bit process that load the dlls and use interprocess communication through COM to talk to a new 64-bit dll which is just a stub forwarding the call from your 64-bit program back and forth.
Your VB gateway is pretty much the same idea, possibly slightly less efficient, but if it's easy for you to write, then go for it.
James Tursa
James Tursa el 7 de Jul. de 2017
Can a 64-bit MATLAB interface with a 32-bit MATLAB through the C/C++ Engine API (which is a COM interface)? I have never tried it.
Walter Roberson
Walter Roberson el 7 de Jul. de 2017
If I understand correctly, the COM interfaces are tagged by 32 vs 64 bits and the other size cannot be accessed.
Guillaume
Guillaume el 7 de Jul. de 2017
It all depends on whether the COM server is in-process (dll) or out-of-process (exe). You can talk to an out-of-process server even if it's not the same bitness. That's the whole concept of the surrogate process described in the blog post I linked above.
In the case of matlab, since it's implemented as out-of-process, yes, you can talk between the two.

Iniciar sesión para comentar.

Lorenzo
Lorenzo el 7 de Jul. de 2017

0 votos

I know that it is not possible to mix the 32 and 64 bit world. My idea is indeed to write the gateway. I'm asking if someone has a better idea and in the care of the gateway exe, if there is a better and common way to interact. My VB or VC skill are limited, and I need to understand how to make the COM connection from the VB side, for example... so any idea is welcome!
Thank you

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Jul. de 2017

Comentada:

el 7 de Jul. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by