dll problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason

    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++programm ingtest\\test.d ll" () 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::DllCl ass()
    {

    }


    DllClass::~DllC lass ()
    {

    }

    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_ATT ACH:
    break;

    case DLL_PROCESS_DET ACH:
    break;

    case DLL_THREAD_ATTA CH:
    break;

    case DLL_THREAD_DETA CH:
    break;
    }

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


  • J French

    #2
    Re: dll problem

    StdCall ???

    On Tue, 20 Jan 2004 15:02:42 +0000 (UTC), "Jason"
    <jason.carney1@ btinternet.com> wrote:
    [color=blue]
    >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++programm ingtest\\test.d ll" () 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::DllC lass()
    >{
    >
    >}
    >
    >
    >DllClass::~Dll Class ()
    >{
    >
    >}
    >
    >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_ATT ACH:
    > break;
    >
    > case DLL_PROCESS_DET ACH:
    > break;
    >
    > case DLL_THREAD_ATTA CH:
    > break;
    >
    > case DLL_THREAD_DETA CH:
    > break;
    > }
    >
    > /* Returns TRUE on success, FALSE on failure */
    > return TRUE;
    >}
    >
    >[/color]

    Comment

    • Jason

      #3
      Re: dll problem


      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++programm ingtest\\test.d ll" () 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:


      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" <jason.carney1@ btinternet.com> wrote in message
      news:bujfuh$icv [email protected] rnet.com...[color=blue]
      > Hello,
      >
      > I am using Dev c++ to create a dll in c++ on windows xp pro. It provided[/color]
      me[color=blue]
      > 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[/color]
      project,[color=blue]
      > 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++programm ingtest\\test.d ll" () 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::DllCl ass()
      > {
      >
      > }
      >
      >
      > DllClass::~DllC lass ()
      > {
      >
      > }
      >
      > int DllClass::runme () {
      > return 9000;
      > }
      >
      >
      > BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */[/color]
      ,[color=blue]
      > DWORD reason /* Reason this function is[/color]
      being[color=blue]
      > called. */ ,
      > LPVOID reserved /* Not used. */ )
      > {
      > switch (reason)
      > {
      > case DLL_PROCESS_ATT ACH:
      > break;
      >
      > case DLL_PROCESS_DET ACH:
      > break;
      >
      > case DLL_THREAD_ATTA CH:
      > break;
      >
      > case DLL_THREAD_DETA CH:
      > break;
      > }
      >
      > /* Returns TRUE on success, FALSE on failure */
      > return TRUE;
      > }
      >
      >[/color]


      Comment

      • Steve Gerrard

        #4
        Re: dll problem


        "Jason" <jason.carney1@ btinternet.com> wrote in message
        news:bukk4e$6rc [email protected] nternet.com...[color=blue]
        >
        > 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();
        > }[color=green]
        > > class DLLIMPORT DllClass
        > > {
        > > public:
        > > DllClass();
        > > virtual ~DllClass(void) ;
        > > int runme(void);
        > > };
        > >
        > > int DllClass::runme () {
        > > return 9000;
        > > }[/color][/color]

        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?


        Comment

        • Jason

          #5
          Re: dll problem


          "Steve Gerrard" <notstevegerrar [email protected]> wrote in message
          news:JdOdnd7Wqr [email protected]. ..[color=blue]
          >
          > "Jason" <jason.carney1@ btinternet.com> wrote in message
          > news:bukk4e$6rc [email protected] nternet.com...[color=green]
          > >
          > > 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();
          > > }[color=darkred]
          > > > class DLLIMPORT DllClass
          > > > {
          > > > public:
          > > > DllClass();
          > > > virtual ~DllClass(void) ;
          > > > int runme(void);
          > > > };
          > > >
          > > > int DllClass::runme () {
          > > > return 9000;
          > > > }[/color][/color]
          >
          > 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?
          >[/color]

          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.
          [color=blue]
          >[/color]


          Comment

          • Steve Gerrard

            #6
            Re: dll problem


            "Jason" <jason.carney1@ btinternet.com> wrote in message
            news:bulsss$pbf [email protected] ernet.com...[color=blue]
            >
            > "Steve Gerrard" <notstevegerrar [email protected]> wrote in message
            > news:JdOdnd7Wqr [email protected]. ..[color=green]
            > >
            > > "Jason" <jason.carney1@ btinternet.com> wrote in message
            > > news:bukk4e$6rc [email protected] nternet.com...[color=darkred]
            > > >
            > > > 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;
            > > > > }[/color]
            > >
            > > I don't get the concept of defining runme() as a member of a class,[/color][/color]
            and[color=blue][color=green]
            > > then being able to export just that function. Is that a feature of[/color][/color]
            the[color=blue][color=green]
            > > DLLIMPORT keyword?
            > >[/color]
            >
            > Perhaps I misled you. runme does not get exported, runmefunc does[/color]
            reflected[color=blue]
            > 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[/color]
            cant[color=blue]
            > deal with objects and member functions.
            >[/color]

            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.


            Comment

            • Jason

              #7
              Re: dll problem


              "Steve Gerrard" <notstevegerrar [email protected]> wrote in message
              news:H8CdnRkJ69 fzqpLd4p2dnA@co mcast.com...[color=blue]
              >
              > "Jason" <jason.carney1@ btinternet.com> wrote in message
              > news:bulsss$pbf [email protected] ernet.com...[color=green]
              > >
              > > "Steve Gerrard" <notstevegerrar [email protected]> wrote in message
              > > news:JdOdnd7Wqr [email protected]. ..[color=darkred]
              > > >
              > > > "Jason" <jason.carney1@ btinternet.com> wrote in message
              > > > news:bukk4e$6rc [email protected] nternet.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,[/color][/color]
              > and[color=green][color=darkred]
              > > > then being able to export just that function. Is that a feature of[/color][/color]
              > the[color=green][color=darkred]
              > > > DLLIMPORT keyword?
              > > >[/color]
              > >
              > > Perhaps I misled you. runme does not get exported, runmefunc does[/color]
              > reflected[color=green]
              > > 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[/color]
              > cant[color=green]
              > > deal with objects and member functions.
              > >[/color]
              >
              > 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.
              >[/color]
              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.
              [color=blue]
              >[/color]


              Comment

              Working...