How do I debug my generic DLL in Microsoft Visual C++ .NET while calling the DLL functions in MATLAB 7.0 (R14) after loading the DLL using the LOADLIBRARY function?

8 views (last 30 days)
I have created a C/C++ DLL in Microsoft Visual C++ .NET and I want to load it in MATLAB via the LOADLIBRARY function. I would then like to debug my DLL in the Microsoft Visual C++ .NET environment when making calls to the DLL functions.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
NOTE: This solution is not officially supported by MathWorks.
Ensure that you have created a Debug build of the DLL in Microsoft Visual C++ .NET.
The following steps demonstrate how to debug the DLL in the Microsoft Visual C++ .NET environment:
1. Open the Visual Studio .NET development environment.
2. Open a New "empty" project.
3. Select File->Add Existing Item... And select the name of the DLL.
4. Select File->Add Existing Item... And select the name of the C/C++ source file.
5. Open the C/C++ source by double-clicking on it in the Solution Explorer frame.
6. Place a break point at the appropriate line of code.
7. Select Project->$PROJECT_NAME settings where $PROJECT_NAME is the name of your project.
8. Under the Configuration Properties, click on "Debugging."
9. Click on "Command" under Action and browse to the MATLAB executable file $MATLABROOT/bin/win32/matlab.exe where $MATLABROOT is the directory in which MATLAB is installed.
10. Click OK.
11. Select Debug->Start or press F5.
12. Click NO if it prompts you to rebuild the out of date project.
13. Click "OK" if it reports that matlab.exe does not contain debugging symbols.
This should open the MATLAB environment after a few moments.
14. Change to the directory location of the DLL using the CD command in MATLAB.
15. Load the library via the LOADLIBRARY function.
16. Call the desired library function via the CALLLIB function. This will start the MSVS 7.0 environment and stop at the break point.
You should now be able to step through the DLL source code as you would any C/C++ applicaton.

More Answers (0)

MathWorks Support

Categories

Find more on C Shared Library Integration 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!