Click to See Complete Forum and Search --> : C++ dll


Gowri kuppa
October 11th, 1999, 10:56 AM
Hello ,

I am realtively new using visual c++. I have 2 questions.
1) I have to make a dll and export classes from c++ 6.0, so that
I can call them from visual basic 6.0. For this purpose do I have to write a COM server dll ? Can this be done using MFC extended dlls ? I made a MFC extended dll , but not able to reference that through VB.

2) I have a Fortran dll prepared on NT that has some exported functions. I am trying to call the dll from C++. I only have the dll , no Lib file or anything , so I tryed to use explicit linking. But my loadlibrary and Getprocaddress fails returning me an error code of 120. But VB is able to call the same dll and give me results .


Any help on these 2 issues will be highly appreciated.

Gowri

Paul McKenzie
October 11th, 1999, 11:33 AM
For question 1, all you need is to declare your C++ DLL functions this way:

// declare an exported DLL function called MyFunc()
extern "C" __declspec(dllexport) __stdcall MyFunc(int);



Then you create a module definition file (.DEF) file:

LIBRARY MYDLL
DESCRIPTION 'This is a test DLL'
...
EXPORTS
MyFunc @1



Add the .DEF file to your project and you will be able to call MyFunc from your VB application.

For problem 2, I would use the QuickView utility that comes with NT and some versions of Windows 95/98. Right click on the DLL name in Windows Explorer and you should see a menu with "Quick View" as one of the entries. If you choose this, you will see the names of the exported files for the DLL. In 32-bit DLL's, the name of the function must match *exactly* with the function name in the DLL; case-sensitivity is very important. For example "DLLFUNC" is not the same as "DLLfunc". This wasn't the case for 16-bit DLL's but it is for 32-bit DLLs.

Regards,

Paul McKenzie

Gowri kuppa
October 11th, 1999, 01:02 PM
Paul,

Thank you very much for responding back to me. However for question 1, I am trying to export classes,
not functions and I would like to reference my class through references in VB. The function exporting
works for me and I alredy used the method you suggested. I am trying to write some classes and I should be able to see and use these classes from VB. I was wondering whether I have to use COM or can I achieve this with MFC extended dlls?

For question 2, I have the source code and def file for the fortran dll. So I am using exact function name.
Infact if I give a spelling mistake, the return code is not 120 instead it is 127.

I appreciate you responding back to me,

Thanks,
Gowri