dll question

J

Jason

Hello, I've got an example from the mingw website of creating a dll. It is
3 files: a header, .c file and another file containing main. I want to use
the dll in VB and it works for tstfunc, but I am not able to use tststr as
it wont export.

header file:

#ifdef BUILD_DLL
// the dll exports
#define EXPORT __declspec(dllexport)
#else
// the exe imports
#define EXPORT __declspec(dllimport)
#endif

// function to be imported/exported
EXPORT int tstfunc (void);

EXPORT long tststr (void); //I want to use function too

..c file

#include <stdio.h>
#include "dllfct.h"

EXPORT int tstfunc (void)
{
return 200;
}

EXPORT long tststr (void) { //am returning a long due to wanting to use
the pointer in VB because
//experimenting with what
values I can return and use from the dll
char p[10];
p = (char *) "hello\0";
return (long *) p;
}

If I do the below it gives me an error at compile time due to an undefined
reference to _imp__tststr, the name of the second function I wish to export.

#include "dllfct.h"

int main ()
{
tstfunc ();
tststr();
return (0);
}

I guess I need to change this to export the second function, but how? What
does it mean?

#ifdef BUILD_DLL
// the dll exports
#define EXPORT __declspec(dllexport)
#else
// the exe imports
#define EXPORT __declspec(dllimport)
#endif



Thanks for any help.
 
T

Thomas Matthews

Jason said:
Hello, I've got an example from the mingw website of creating a dll. It is
3 files: a header, .c file and another file containing main. I want to use
the dll in VB and it works for tstfunc, but I am not able to use tststr as
it wont export.

DLLs are not part of the _standard_ C++ language, which is discussed
in this newsgroup, so you will have to ask elsewhere, such as a
newsgroup dedicated to your compiler or platform. See the FAQ link
below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
L

Lew Pitcher

DLLs are not part of the _standard_ C++ language, which is discussed
ITYM
_standard_ C language
---------- = --------
This is comp.lang.c, after all.

in this newsgroup, so you will have to ask elsewhere, such as a
newsgroup dedicated to your compiler or platform. See the FAQ link
below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
 
C

Christopher Benson-Manica

Thomas Matthews said:
DLLs are not part of the _standard_ C++ language, which is discussed
in this newsgroup, so you will have to ask elsewhere, such as a

They aren't part of standard C either, which is the *real* subject of
this newsgroup.

Haste makes waste, eh? ;)
 
J

Jason

Lew Pitcher said:
ITYM
_standard_ C language
---------- = --------
This is comp.lang.c, after all.

What's the difference between asking how to use a library function for a
string or something else(not standard c, right?) and asking about the code
appropriate for compiling something into a dll. If the code I included is
something other than c then let me know, I've seen people in here ask about
all sorts not strictly part of the standard c language...and why refer
someone to FAQ, it just adds insult to injury.
 
J

Jack Klein

What's the difference between asking how to use a library function for a
string or something else(not standard c, right?) and asking about the code
appropriate for compiling something into a dll. If the code I included is
something other than c then let me know, I've seen people in here ask about
all sorts not strictly part of the standard c language...and why refer
someone to FAQ, it just adds insult to injury.

Yes, it includes something other than C. It includes such
non-standard things as:

__declspec(dllexport)

references to Visual Basic

#include "dllfct.h"

One can memorize the ANSI/ISO C language standard (any version) and
not come upon the definition of any of these things. They do not
exist in standard C, nor do they exist in compilers or under operating
systems other than Microsoft's.

There is no such thing as a DLL in the C language, and there is no
standard C code that can be used to make one, although one can
probably contain standard C code along with the non-standard code that
is necessary.

DLLs are not a part of C or any other programming. They are a part of
Windows and off-topic here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top