-1

Fair warning, I'm relatively new to using Matlab and Visual Studio.

I've been trying to create code that I can use to communicate through a USB to an arduino. I found some example code using a library called CmdMessenger, the examples provided code to load onto the Arduino and code to be built using Visual Studio. By default the examples run on command line, but I set them to create .DLL files and used NET.addAssembly to add these files to Matlab and use them. Initially this worked just fine and I was able to send a command to my arduino to toggle an LED for a period of time before sending a confirmation signal back to Matlab.

Unfortunately I needed to make changes to the example code so I added some of my own code and created a new DLL using a different piece of example code that better fit my needs. I was able to use "a = NET.addAssembly" again and use the namespace in Matlab. Then I made more changes, cleared the variable "a", and tried to use "a = NET.addAssembly" again, but this time I got an error message.

In fact, I went and tried to add the previous example DLL I'd used, and now it too gives me the same error message. I've searched and found nothing that's helped me rectify this situation.

The command I gave was: "a = NET.addAssembly('C:\DLL\SendAndReceiveArguments.dll');"

The error message I received was:

Message: Could not load file or assembly 'file:///C:\DLL\SendAndReceiveArguments.dll' or one of its dependencies. An attempt was made to
load a program with an incorrect format.
Source: mscorlib
HelpLink:

Any suggestions for troubleshooting this problem would be greatly appreciated.

TomServo
  • 7,248
  • 5
  • 30
  • 47
Josh
  • 1
  • 1
  • You should try get more information doing a google search of the error and coming back here with your findings – fatiu Jul 12 '21 at 12:23
  • Well I have a few new findings. Firstly, an interesting result to an experiment. I tried using NET.addAssembly('C:\DLL\SendAndReceiveArguments.dll') with a .dll that I knew wouldn't work. I got the error as described above. I then replaced the fill in C:\DLL with one I knew worked. I then used the same command, it also threw the same error. So I closed Matlab, reopened it, and tried the command once more with the dll I knew worked. It loaded without issue. I still don't know why the other dll isn't working, but I'll be researching more today. I'll post what I find. – Josh Jul 13 '21 at 13:51
  • I could still use help with this issue. I went on a wild goose chase yesterday trying to use "regsvr32", but I get a new error stating: The module "SendAndReceiveArguments.dll" was loaded but the entry-point DllRegisterServer was not found. Make sure that "SendAndReceiveArguments.dll" is a valid DLL or OCX file and then try again. No clear explanation of how to determine if the DLL is valid, and I get the same error when I try to use the version of "SendAndReceiveArguments.dll" that actually works with Matlab, so I have no idea if I'm close to being on the right track. – Josh Jul 14 '21 at 15:36

1 Answers1

0

5 minutes after my last post and I figured it out from another question asked on this very site. Shows how well my I did my searching up to this point.

The first answer to this question led me down the right path. All I needed to do was right-click on the project in Visual Studio and select 'Properties'. In this menu select 'Build' from the left panel and make sure that 'Platform target:' was set to 'Any CPU' (mine was set to x86 for some reason).

Image: Under the project properties, go to the 'Build' menu and make sure 'Platform target:' is set to 'Any CPU'

With this change my project loaded into Matlab without issue.

Sorry to waste anyone's time who searched for an answer I could have found myself, and thanks for your time.

Josh
  • 1
  • 1