hey all, I just joined this community. I have been programming quite a bit in C/C++, however, this is the first time i am doing something like this. I have the Microsoft VC++ 6 package. The idea is to use the functions i have already written in the past( a lot of them ), in a current MATLAB project. The solution that i can think of is to convert the functions and the libraries into a DLL so that i can use loadlibrary in MATLAB and call them out. however, i cant seem to make DLL files. I have done some reading, but it is not helping. Can anyone help me out with this. The problem is to build DLLs in VC++ and then call them using MATLAB. In case there is a better method to call the C++ functions in MATLAB, i am open to that too. I just need to get some stuff working in MATLAB without having t recode it, since recoding will take me a HELL lot of time. Help me out folks ... Thanks

Cheers

I could tell you how to do it in ms visual c++4 if thats ok?

Yes that could work too, i may get some hints based on that. I am trying another approach now which is very lenghty and "dirty" to say the least. I am trying to get executables. I am making executables of all the functions, due to which i am loosing the nice class structure i had built. I will then be calling these executables in MATLAB, using the system command.

However, if you can get me to make a DLL to be loaded in MATLAB, it would be great.

Thanks a lot

Cheers

Ill get back to you but it may be a while as I will have to reinstall the software to check it out first - ok?

in VC++ 6.0 IDE create a "win32 Dynamic-Link Library" project. Step 1 of the wizard has 3 radiao buttons select "a DLL project that exports some symbols" then press Finish button. The wizard will generate the DLL project. Look at the *.cpp and *.h files. They will show you how to add your own functions and how to "export" them so that they can be used by other applications. Just copy-past the functions or files into that project, export them as illusterated.

Thanks Proliant .. appreciate it ..

Ancient.... i have already done that. It makes my DLLs.. but the problem is loading them into MATLAB. When i load them into MATLAB, it does not like it. It says, that all the functions mentioned in the header are missing. I am trying to get around that. Got any ideas ?

Cheers

How are you using the DLL'S? You cant just call them and pass arguments like you would an .EXE file.

first i make the DLLs, with some extra lines of code in the DLLMain() function. This is the function that will call the appropriate original function and pass paramteres to them as needed. The call to DLLMain with the appropriate parameters will be made through MATLAB. This is my understanding.

sounds like the function names in the dll have been mangled, so mathlib doesn't know how to handle that. In the dll, use extern "C" if you don't need c++ classes to keep the compiler from mangling the names.

extern "C"
{
   void _dllexport foo();
}

DllMain() is called by the os, not directly by using applications. Its sortof like a c++ class constructor/destructor in that it is called then the DLL is loaded into memory and again just before exit.

Sorry but I cant figure it out for you as I cant install VC++ 4 on my XP machine as it wants to install IE 1 and says I dont have it. If I click cancel install aborts and I cant just copy the files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.