64 bit 32 bit Compatible Standalone App
Show older comments
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
John D'Errico
on 30 Jul 2014
In general, YOU did something. MATLAB is not out to get you. Well, probably not.
Accepted Answer
More Answers (2)
Robert Cumming
on 30 Jul 2014
Edited: Robert Cumming
on 30 Jul 2014
1 vote
Does this question describe and answer your problem? Or is it a different issue.
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
Salaheddin Hosseinzadeh
on 30 Jul 2014
Image Analyst
on 30 Jul 2014
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.
Salaheddin Hosseinzadeh
on 30 Jul 2014
Image Analyst
on 16 Oct 2014
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
Salaheddin Hosseinzadeh
on 16 Oct 2014
Edited: Salaheddin Hosseinzadeh
on 16 Oct 2014
Sean de Wolski
on 16 Oct 2014
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.
Image Analyst
on 16 Oct 2014
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
Sean de Wolski
on 16 Oct 2014
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.
Salaheddin Hosseinzadeh
on 16 Oct 2014
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!