469,290 Members | 1,866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

dll problem

Hello,

I am using Dev c++ to create a dll in c++ on windows xp pro. It provided me
with a template and I added a simple function to return an int as a test.
It compiled the dll ok and I added a reference to a Visual basic 6 project,
yet when I call it VB complains about run time error 453, "cant find dll
entry point 'funcname'". Can anybody show me what I am doing wrong, do I
need to create a definition file and if so how?

I have included the declaration in VB and the c++ code below:

Thanks for any help or advice.
Private Declare Function runme Lib "d:\c++programmingtest\\test.dll" () As
Integer
dll.h file:

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
int runme(void);

private:

};

#endif /* _DLL_H_ */

dllmain.cpp file:

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}
DllClass::~DllClass ()
{

}

int DllClass::runme() {
return 9000;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being
called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}

/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
Jul 17 '05 #1
6 5545
StdCall ???

On Tue, 20 Jan 2004 15:02:42 +0000 (UTC), "Jason"
<ja***********@btinternet.com> wrote:
Hello,

I am using Dev c++ to create a dll in c++ on windows xp pro. It provided me
with a template and I added a simple function to return an int as a test.
It compiled the dll ok and I added a reference to a Visual basic 6 project,
yet when I call it VB complains about run time error 453, "cant find dll
entry point 'funcname'". Can anybody show me what I am doing wrong, do I
need to create a definition file and if so how?

I have included the declaration in VB and the c++ code below:

Thanks for any help or advice.
Private Declare Function runme Lib "d:\c++programmingtest\\test.dll" () As
Integer
dll.h file:

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
int runme(void);

private:

};

#endif /* _DLL_H_ */

dllmain.cpp file:

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}
DllClass::~DllClass ()
{

}

int DllClass::runme() {
return 9000;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being
called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}

/* Returns TRUE on success, FALSE on failure */
return TRUE;
}


Jul 17 '05 #2

This is where I get to answer my own question after much effort searching
the internet and piecing together the information:

I needed to declare this for getting a string into VB from Dev c++:

extern "C" __declspec( dllexport ) __stdcall char * Hello();

extern "C" __declspec( dllexport ) __stdcall char * Hello() {
//c++ code
return "dsjfkldsj\0";
}

In VB:
Private Declare Function Hello Lib "d:\c++programmingtest\\test.dll" () As
long

the long returned is now a pointer to a null-terminated string, use
copymemory to extract it, this website in the hexdump code as a nice
function to convert a long to a string:
http://www.mvps.org/vb/index2.html?samples.htm

This works better than what i was doing for returning an int:

extern "C" __declspec( dllexport ) __stdcall int runmefunc();

extern "C" __declspec( dllexport ) __stdcall int runmefunc() {
return runme();
}

everything else stays the same as below.

thanks to me in retrospect...

regards
jason

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@titan.btinternet.com...
Hello,

I am using Dev c++ to create a dll in c++ on windows xp pro. It provided me with a template and I added a simple function to return an int as a test.
It compiled the dll ok and I added a reference to a Visual basic 6 project, yet when I call it VB complains about run time error 453, "cant find dll
entry point 'funcname'". Can anybody show me what I am doing wrong, do I
need to create a definition file and if so how?

I have included the declaration in VB and the c++ code below:

Thanks for any help or advice.
Private Declare Function runme Lib "d:\c++programmingtest\\test.dll" () As
Integer
dll.h file:

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
int runme(void);

private:

};

#endif /* _DLL_H_ */

dllmain.cpp file:

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}
DllClass::~DllClass ()
{

}

int DllClass::runme() {
return 9000;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}

/* Returns TRUE on success, FALSE on failure */
return TRUE;
}

Jul 17 '05 #3

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@hercules.btinternet.com...

This works better than what i was doing for returning an int:
extern "C" __declspec( dllexport ) __stdcall int runmefunc();
extern "C" __declspec( dllexport ) __stdcall int runmefunc() {
return runme();
}
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
int runme(void);
};

int DllClass::runme() {
return 9000;
}


I don't get the concept of defining runme() as a member of a class, and
then being able to export just that function. Is that a feature of the
DLLIMPORT keyword?
Jul 17 '05 #4

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:Jd********************@comcast.com...

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@hercules.btinternet.com...

This works better than what i was doing for returning an int:
extern "C" __declspec( dllexport ) __stdcall int runmefunc();
extern "C" __declspec( dllexport ) __stdcall int runmefunc() {
return runme();
}
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
int runme(void);
};

int DllClass::runme() {
return 9000;
}

I don't get the concept of defining runme() as a member of a class, and
then being able to export just that function. Is that a feature of the
DLLIMPORT keyword?


Perhaps I misled you. runme does not get exported, runmefunc does reflected
in any VB declarations. the extern c functions wrap around any
object-oriented c++ code so windows can use it as a c function, as it cant
deal with objects and member functions.

Jul 17 '05 #5

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@sparta.btinternet.com...

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:Jd********************@comcast.com...

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@hercules.btinternet.com...

This works better than what i was doing for returning an int:
extern "C" __declspec( dllexport ) __stdcall int runmefunc();
extern "C" __declspec( dllexport ) __stdcall int runmefunc() {
return runme();
}
> class DLLIMPORT DllClass
> {
> public:
> DllClass();
> virtual ~DllClass(void);
> int runme(void);
> };
>
> int DllClass::runme() {
> return 9000;
> }
I don't get the concept of defining runme() as a member of a class, and then being able to export just that function. Is that a feature of the DLLIMPORT keyword?


Perhaps I misled you. runme does not get exported, runmefunc does

reflected in any VB declarations. the extern c functions wrap around any
object-oriented c++ code so windows can use it as a c function, as it cant deal with objects and member functions.


I think that is what surprises me. It seems like the wrapper runmefunc
is able to call the function runme, without bothering to create an
instance of the DllClass in which it is defined.
Jul 17 '05 #6

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:H8********************@comcast.com...

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@sparta.btinternet.com...

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:Jd********************@comcast.com...

"Jason" <ja***********@btinternet.com> wrote in message
news:bu**********@hercules.btinternet.com...
>
> This works better than what i was doing for returning an int:
> extern "C" __declspec( dllexport ) __stdcall int runmefunc();
> extern "C" __declspec( dllexport ) __stdcall int runmefunc() {
> return runme();
> }
> > class DLLIMPORT DllClass
> > {
> > public:
> > DllClass();
> > virtual ~DllClass(void);
> > int runme(void);
> > };
> >
> > int DllClass::runme() {
> > return 9000;
> > }

I don't get the concept of defining runme() as a member of a class, and then being able to export just that function. Is that a feature of the DLLIMPORT keyword?

Perhaps I misled you. runme does not get exported, runmefunc does

reflected
in any VB declarations. the extern c functions wrap around any
object-oriented c++ code so windows can use it as a c function, as it

cant
deal with objects and member functions.


I think that is what surprises me. It seems like the wrapper runmefunc
is able to call the function runme, without bothering to create an
instance of the DllClass in which it is defined.

oops i just realised what i did. i did not compile that bit...i jsut added
it into the email to illustrate the wrapper function, forgetting to create
the object first - doh.

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Kostatus | last post: by
117 posts views Thread by Peter Olcott | last post: by
18 posts views Thread by Ian Stanley | last post: by
28 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Mike Collins | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.