DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Building DLLs in VC++ (http://www.daniweb.com/forums/thread31689.html)

openhiem Sep 2nd, 2005 5:05 pm
Building DLLs in VC++
 
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

jbennet Sep 7th, 2005 12:23 pm
Re: Building DLLs in VC++
 
I could tell you how to do it in ms visual c++4 if thats ok?

openhiem Sep 7th, 2005 12:30 pm
Re: Building DLLs in VC++
 
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

jbennet Sep 7th, 2005 2:09 pm
Re: Building DLLs in VC++
 
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?

Ancient Dragon Sep 7th, 2005 2:15 pm
Re: Building DLLs in VC++
 
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.

openhiem Sep 7th, 2005 2:28 pm
Re: Building DLLs in VC++
 
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

jbennet Sep 8th, 2005 11:53 am
Re: Building DLLs in VC++
 
How are you using the DLL'S? You cant just call them and pass arguments like you would an .EXE file.

openhiem Sep 8th, 2005 1:09 pm
Re: Building DLLs in VC++
 
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.

Ancient Dragon Sep 8th, 2005 3:24 pm
Re: Building DLLs in VC++
 
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.

jbennet Sep 16th, 2005 3:28 am
Re: Building DLLs in VC++
 
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.


All times are GMT -4. The time now is 11:23 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC