Solved

Functions are not exported from Visual C++

Posted on 2001-08-23
8
343 Views
Last Modified: 2013-12-14
I am compiling a MSVC++ API DLL (win32) project, and cannot seem to "find" my exported functions in the DLL. (Using Quickview - there are no exports.  When linking to DLL - it says function not found)

I have tried using the __declspec ( dllexport ) prefix on the function prototypes (as per documentation) and also using the DEF file with an EXPORTS section.

Now - one funny thing I am doing is:  My functions are in "C" files only.  I am using the extern wrapper for the prtototypes.
ie.
extern "C"
{

protottype....

}
This allows me to call the functions from a C++ file.
Could this be messing up my export?  Do I have to provide C++ stubs for my C functions?


(In Borland C++ 5.02 this DLL compiles, exports and runs perfectly - have to port this to Microsoft unfortunately)

Thanks in advance
0
Comment
Question by:gmleeman
8 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6420884
Listening...
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 250 total points
ID: 6420899
1. Do you use "C:\Program Files\Microsoft Visual Studio\Common\Tools\DEPENDS.EXE" to check it.
VC will add "_" prefix begin the function's name.So you should check it.
_YourFunName

2. You can add a DEF file to get the pure function name.
LIBRARY  XXX
DESCRIPTION 'fsdafsadfsaf'

EXPORTS
     YourFunName
     YourFunName2

3. Of couse, you should add extern "C", or the exported name will in C++ style. maybe _Xxxx@4 ro ?Xxxx@8
@4, @8 is the stack size which the function need, is the total of all parameter's size.
0
 
LVL 1

Expert Comment

by:AlexReser
ID: 6421096
your_dll.h
=========================
#if !defined(_YOURDLL__INCLUDED_)
#define _YOURDLL__INCLUDED_

#ifdef __cplusplus
extern "C" {
#endif

__declspec( dllexport ) int YourCoolExport();

#ifdef __cplusplus
}
#endif

#endif // _YOURDLL__INCLUDED_
=========================

your_dll.c
=========================
#include "your_dll.h"

int YourCoolExport()
{
   return 0;
}
=========================

.def file is not necessity
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6421184
Can you show your code?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6424331
A def file is useful if you wish to keep the export numbers fixed - this is useful if you have a library and wish to upgrade it in the future and keep compatibility with programs compiled against older DLLs - this is the techniques that the MFC dlls use
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6425732
>>When linking to DLL - it says function not found)

One does not link to a DLL (exception: runtime linking via LoadLibrary/GetProcAddress).  Have you put the .LIB file in the list of files for the linker to use?  Alternative, place...

  #pragma comment(lib,"mylib.lib")

into a source file that calls your exported fn.

That does not explain why QuickView can't see the exports (unless it is an old 16-bit version of QuickView)

Also, dump the EXPORT section of the DEF file.  It just confuses the issue.  The__declspec( dllexport ) places all of the needed info into the LIB file.

-- Dan
0
 

Expert Comment

by:findufin
ID: 6426276
see the BeyondWu response :  "depends" will show you the right thing !

because with visual c++ in release mode, Quickview hide exported functions !
0
 
LVL 3

Author Comment

by:gmleeman
ID: 6427577
Tx BeyondWu and others

Your answer is completely correct (except you omitted the declspec thingy) . I managed to get it working as an API DLL by using:
-extern "C" around prototypes
-__declspec(_dllexport) as a prefix to the function defn.
-a DEF file with the EXPORTS section, etc.

Also - the other response is right. One still cannot view the exported functions in QuickView. (Although they are exported in pure API form). However, The Dependency viewer in MSVC++ does show the exported functions properly.
Thanks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reference external folders in Visual Studio 4 77
Least Squares Curve Fitting 4 61
Create a path if not exists 7 69
Which Linux flavors will this run on? 6 76
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now