Compiling with a .def file in VC++ 2008 Express

Hi,

I am trying to create a DLL with functions that I would like to use in MS Excel. I am receiving the error msg "Can't find DLL entry point ..." when I step debug a test sub-routine that includes the C++ function.

I believe I am having trouble w/ getting the compilier to "attach" the .def file that I created with the clean names to the process. I suspect this because I edit only the .def file, re-compile the project, and the compiler responds that the build is up-to-date. Can someone please explain to me how to properly attach a .def file to a build/project for DLLs in Visual C++ 2008 Express Edition? Or some advice on how to sidestep this problem all together? Thank you for your help.
Found this:

Using a DEF file: http://msdn.microsoft.com/en-us/library/d91k01sh%28VS.80%29.aspx

As an alternative to the DEF file, you could mark your functions with __declspec(dllexport). If you are using C++, then you might want to use extern "C" __declspec(dllexport). See:

http://msdn.microsoft.com/en-us/library/a90k134d%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/d91k01sh%28VS.80%29.aspx
I am at the office now and am using Dev-C++ to attempt this.

I am been stuck on this all morning, trying the "__declspec(dllexport)" method, editing the .def file, and extern "C". I just can't get it to work. Please help as I am tired on being stuck on this problem!

SOME HELPFUL INFORMATION:
I am a beginner. I am trying to re-create the example on pp.53-64 in the following pdf link: http://www.maths.manchester.ac.uk/~ahazel/EXCEL_C++.pdf

Square.cpp
1
2
3
4
__declspec(dllexport) double __stdcall square_in_C(double& arg) 
{
       return (arg * arg);
}


Square.def
1
2
3
LIBRARY MyXLLib
EXPORTS
 square_in_C @1


VBA Script
1
2
3
4
5
6
7
8
9
10
11
12
'Prototype the interface of the function from the library
Declare Function square_in_C _
    Lib "C:/Documents and Settings/Administrator/Desktop/MyXLLib/MyXLLib.dll" (arg1 As Double) As Double


Sub test_square_in_C()
    
    Dim t As Double
    
    t = square_in_C(10.5)
    
End Sub 
Last edited on
If you attempt to export the functions using __declspec(dllexport), then get rid of the DEF file.

Besides, if you use _declspec(dllexport), you also need to use extern "C" because you will get a different function name if you don't.

1
2
extern "C" __declspec(dllexport) double __stdcall square_in_C(double& arg)
{ ... }


I am a Visual C++ guy, so I cannot help further in other compilers/linkers. Good luck with this.
IT WORKS !!!!!!!!!!! Thank you so much for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

No seriously, thank you!!!!
Topic archived. No new replies allowed.