64 bit 32 bit Compatible Standalone App

Guys Thank You Very Much.
It's awesome that you share your experties on this website, it wouldn't be so helpful and useful without you, thanks for your dedication ;)
I've just created a satandalone app according to Roberts comment, and it works perfectly on Win 64 and 32.
It couldn't be any better.
Many Regards,
%% Previously Posted Problem Hello Everyone.
I have a TTi 12104 Waveform generator comes with drivers and dll file + a console C app that allows sendin simple commands to the device and make sure it's connected and responds.
Device has a single driver for both 64bit and 32bit version of windows(tested on win 7 64bit and XP 32bit), device is perfectly installed on win 7 64bit (with the same driver used for win xp 32 bit) and console app, which uses the the same 32 bi dll file, also works flawless on 7 64 bit.
So the DLL file works on both 32 and 64 bit of windows, this is I'm sure about as I tested myself.
Although when tried to load the same dll into MATLAB 64bit there was this error:
...\AWGUSB.DLL is not a valid win32 application.
How come it works in C (on 64bit win 7) but not MATLAB 64bit on the same machine and same windows?! I previously used the same device in matlab 32 bit but I can not use it in 7 64 in MATLAB, outside matlab it's fine with 64bit windows.
I attached the header file maybe that gives a clue. Thanks for your help.

1 Comment

In general, YOU did something. MATLAB is not out to get you. Well, probably not.

Sign in to comment.

 Accepted Answer

You can deploy a 32 bit version which will run on a 32 bit or a 64 bit computer.
You can't compile a 64 bit from a 32 bit.
Your DLL needs to be compatible with your version of Matlab.
Its perfectly fine to run a 32 bit Matlab on 64 bit windows. In such a scenario your deployed app will run on both 32 and 64 bit machines. It will be 32 bit

2 Comments

OH! Holy Robert! LOL
Such a relief!
Thanks for your answer Robert! If that works which is similar to what Image Analyst also suggested, then it would be great!
So, according to your answer, If I use a 32bit MATLAB in 64bit windows, then the resulted standalone app will run on both win 64 and 32 and my DLL problem will be solved as well?! If this works then I will always make standalone apps in a 64bit windows but with 32bit MATLAB so it would be both 64 and 32 bit compatible!!
I've heard about using 32bit MATLAB, but nobody talked about the resulted standalone app compatibility.
Unbelievable! I'll try it tomorrow as soon as I got a 32bit matlab on the 64bit machine and I'll let you know about the results.
Thank you so so so much experts!
:)
Hi Dear Robert,
Thanks so much for your answer.
As you said, the generated standalone app with a 64machin 32bit MATLAB parents, is compatible with both version of windows!
That's so cool.
Many Regards, Sala

Sign in to comment.

More Answers (2)

Robert Cumming
Robert Cumming on 30 Jul 2014
Edited: Robert Cumming on 30 Jul 2014
p.s. I'm sure your picture has nothing to do with why you didn't get a comment/answer....
A DLL will be 32bit or 64bit (as stated in Walters answer in the link) so you wont be able to load the 32bit from a 64bit exe (i.e. your 64bit matlab).
How come it works in C and not Matlab - well thats like apples and oranges - you not comparing like for like.
You can use the DLL with 32 bit Matlab on a 64 bit computer, or you will need a 64 bit DLL.

3 Comments

As I said, I can't tell the difference between apple and orange. It may be crystal clear to you, but it's absolutely unbelievable to me, I would blame the MATLAB, as apparently it cannot load the file, otherwise the file is ok! These ppl I'm working for pushed me to use Labview, but I stood behind MATLAb, made them purchase it, and now it's letting me down!
Don't give up. You can install both 32 bit and 64 bit MATLAB, even both on the same computer. If it's a 32 b it DLL, you'll just need to use 32 bit MATLAB like Robert said. I have to do that with one of my programs that needs to use a DLL for which there's only a 32 bit version. Sure it would be nice if 64 bit MATLAB could use 32 bit DLLs, but it can't so we just need to figure out what to do as a workaround and get on with life.
Hi Image Analyst
Thanks so much for your attention again ;)
I heard about installing a 32bit MATLAB on 64bit machine, but finally I would like to create a standalone application for 64 bit windows, Can I do that from a 32bit MATLAB?!
It's getting a bit confusing, I guess.
I made a standalone application in win xp 32bit using DLL file What I want to do is to create the same app for 64 bit Windows.
So I found a 64bit machine, with 64bit version of MATLAB on it and tried to change the dll files for other devices and create another standalone application from the 64bit machine!
I'm wondering if I need to do this at all! Maybe I can make the 64bit app in win xp 32bit instead of switching to another windows(64bit)!
Is it possible to deploy the 64bit version from matlab 32 bit?
If i install a 32bit version of MATLAB on64 bit machine, is the standalone app 64bit compatible or 32 bit?! :(
I'm in the land of unknown, hoping that u experts can help me.
Thanks a lot

Sign in to comment.

You mgiht find my GetOS() function useful. See attached.
% Returns how many bits the MATLAB version is, by calling computer(),
% AND how many bits the computer is by chekcing a registry entry.
function [operatingSystem, howManyOSBits, howManyMATLABbits] = GetOS()
As an example of where to use it, I have a script called compile.m that does the compilation. For example if I need to compile something for a 32 bit computer user, I need to make sure I'm not running 64 bit MATLAB. So my compile script has this code at the beginning:
% Make sure I'm running the 32 bit version before compiling.
[operatingSystem, howManyOSBits, howManyMATLABbits] = GetOS()
if howManyOSBits == 64
errorMessage = sprintf('You are running 64 bit Windows and you need to be running 32 bit Windows.');
WarnUser(errorMessage);
return;
end
promptMessage = sprintf('About to compile myApp.m\nHave you changed the startup.m file already?');
button = questdlg(promptMessage, 'Yes - Continue', 'Yes - Continue', 'No - Cancel', 'Yes - Continue');
if strcmp(button, 'No - Cancel')
edit startup.m;
return;
end

5 Comments

Hi Image Analyst,
Thanks for the GetOS, I didn't know about winregquery command.
I looked at the code you posted in your answer, and I noticed the startup.m which I had a problem with it as well. I have a startup which adds my own developed matlab codes to matlab path so I don't have to do it manually each time I need them. But, it was causing me a problem after creating standalone apps, by looking at the log file of the app I realized that startup is somehow included in the standalone app and it changes the path of everything and program failed to find dll files and ... I thought my startup.m is not coded correctly and I probably made a mistake in it so that it somehow effects the standalone apps.
Is startup.m normally gets into the standalone apps and runs before they even load and execute? Cuz such behavior is not mentioned in MATLAB help!
All the best, SH
IA, you can use the mexext function to tell you the mex extension for the MATLAB instance you are using. This will tell you if you're running 32bit ML on a 64bit OS.
Sean, Seems that it's about the same as computer() - any advantages to using mexext?
Salaheddin:
Yes, that's correct - your startup gets executed by your compiled program when the compiled program runs. Because there may be stuff that you want to do on your development computer that you don't want to happen when your end user runs it on the target computer, you can use isdeployed to put different code in there. For example, here's a snippet from my startup.m file:
% Compiling applications will build in your startup.m file into the executable.
% Do you have a startup.m file that calls addpath? If so, this will cause run-time errors.
% As a workaround, use isdeployed to have the addpath command execute
% only if running from the MATLAB development environment.
function startup()
try
fprintf(1, 'Beginning to run startup.m . . .\n');
startupMFileWasRun = true;
% userFolder = ctfroot % Initialize
format compact;
userpath('reset');
if(~isdeployed)
% Running in the MATLAB development environment.
% fprintf('Assigning default path...\n');
% restoredefaultpath;
% Add the Utilities folder and all subfolders to the search path.
fprintf('Adding D:/Matlab/work/Utilities to path...\n');
addpath(genpath('D:/Matlab/work/Utilities'));
% Add the Lumenera folder and all subfolders to the search path.
fprintf('Adding C:/Program Files/MATLAB/Lumenera Camera to path...\n');
% addpath(genpath('D:/Matlab/Lumenera Camera'));
addpath(genpath('C:\Program Files\MATLAB\Lumenera Camera'));
% Add the work folder and subfolders to the path.
fprintf('Adding D:/Matlab/Work to path...\n');
% addpath(genpath('D:/Matlab/Work'));
% Add just the subset that I need.
addpath(genpath('D:/Matlab/Work/3DImageIO'));
addpath(genpath('D:/Matlab/Work/Utilities'));
addpath(genpath('D:/Matlab/Work/Thresholding'));
javaclasspath('D:/Matlab/Apache Commons/commons-configuration-1.6/commons-configuration-1.6.jar');
cd 'D:/Matlab/work'
fprintf('Saving path...\n');
% savepath;
filebrowser; % Won't work with compiled programs.
fprintf('Rehashing toolbox cache...\n');
rehash toolboxcache;
else % It's running a compiled program on an end user's computer.
userFolder = pwd;
% userFolder = 'C:/Program Files/MATLAB/PG_Custom/myApp'; % 32 bit system!
% echo on;
fprintf(1, 'Startup.m is attempting to change the current folder to %s . . .\n', userFolder);
if exist(userFolder, 'dir') == 7
cd(userFolder)
fprintf(1, ' SUCCESS! Changed the current folder to %s\n', userFolder);
else
% Did not find it. Try switching to the other Program Files Folder.
fprintf(1, ' FAILED! Warning: Failed when it tried to change the current folder to the non-existent folder below:\n %s\n', userFolder);
userFolder2 = userFolder;
if strfind(userFolder, 'Program Files (x86)')
% It's x86. Take that out.
userFolder2 = strrep(userFolder, 'Program Files (x86)', 'Program Files');
elseif strfind(userFolder, 'Program Files')
% No x86. Add it in.
userFolder2 = strrep(userFolder, 'Program Files', 'Program Files (x86)');
end
fprintf(1, ' Trying other Program Files folder:\n %s\n', userFolder2);
if exist(userFolder2, 'dir') == 7
userFolder = userFolder2;
cd(userFolder)
fprintf(1, ' SUCCESS! Changed the current folder to %s\n', userFolder);
else
fprintf(1, ' FAILED! Warning: did not find that folder either.\n');
end
end
fprintf(1, ' The current folder is now %s\n', pwd);
end
fprintf(1, 'Done running startup.m.\n');
% warnStruct = warning('query', 'last')
catch ME
% If there's no catch, then a compiled program will just quit completely
% if it encounters an error. Let's use a try/catch to see if we can get
% it to try to continue running the program instead of just aborting.
errorMessage = sprintf('Error running startup.m:\n%s', ME.message);
fprintf(1, '\n%s\n', errorMessage);
end
Computer tells you the computer architecture. I saw the comment in your getOS function that said:
% % I don't know how to detect if you're running MATLAB 32 under Windows 7/64.
mexext is how you do that.
Thanks a lot Image Analyst.
isdeployed sounds quite interesting, I can discriminate between the MATLAB session mode & deployed apps. Awesome!

Sign in to comment.

Categories

Products

Community Treasure Hunt

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

Start Hunting!