Results 1 to 16 of 16

Thread: Can't find DLL entry point...

  1. #1

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157

    Can't find DLL entry point...

    Hi,
    I have created a simple DLL with Dev-C++. The DLL .CPP file has this:

    Code:
    #include "C:\Dev-C++\programs\dll2\MainDll.h"
    #include <stdio.h>
    #define EXPORT __declspec(dllexport)
    
    EXPORT void __stdcall printMessage()
    {
      printf("Hello");
    }
    The .H file has a function prototype for the above code.

    The DLL file is created just fine. I can use this DLL in my other Dev-C++ programs without any problem.

    I am trying to use this in VB6

    Code:
    Private Declare Function printMessage Lib "C:\Dev-C++\programs\dll2\dllproj.dll" ()
    This produces "cannot find DLL entry point".

    I have not included any windows references inside my DLL code. I am trying to use this regular DLL with VB. I think that is my problem.

    I have searched this site for solutions but none seem to fit. Any input would be welcomed.

    Regards,
    ChuckB

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You haven't searched thourougly enough. This has been handled at least five times that I can think of.

    Whatever.

    When making a dll that can be used in VB you don't use _declspec(dllexport), you write a .def file. A .def file looks like this:

    LIBRARY "filename"

    EXPORTS
    func1
    func2
    func3
    ...

    This must somehow be given to the compiler/linker, then it should work.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi,
    I have tried 8 different methods to declare a function so I can create a DLL to be read by VB. I am not using a .DEF file. I have done a lot of reading and searching on the net...so some of what is written below is understandable...however, as you can see, I am just fishin...

    The following function declarations result in an error message "Cannot find DLL entry..."

    Code:
    EXPORT void __stdcall printMessage()       
    extern "C" void __stdcall printMessage()  
    extern "C" __declspec(dllexport) void __stdcall  printMessage()
    __stdcall void printMessage() 
    __stdcall __declspec(dllexport) void printMessage() 
    extern "C" __declspec(dllexport) __stdcall void printMessage()
    __declspec(dllexport) __stdcall void printMessage() //cannot find
    __declspec(dllexport) void __stdcall printMessage()
    This was a nice error, because it meant I got past the above error. It read "bad DLL calling convention..."

    Code:
    extern "C" __declspec(dllexport) void printMessage()
    So, here is where I am stuck using Dev-C++ or VC++ to make the above DLL function work in VB. Any help is always appreciated. I need to get the declaration right....or use a Definition file...


    Regards,
    ChuckB

  4. #4

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    CornedBee,

    I thought 6 hours on this site and others searching for clues was sufficient... however, most threads are incomplete...this isn't so bad since most great programmers are lousy at explaining things. I think this is because they may be thinking something complex, assume the reader had a mind meld capability, and then writes just enough to tease:-) Whatever!

    I have created DEF files...4 to be exact...using of course various formats found on this site (including your example) and others on the internet that doesn't work any better. I have noticed that Dev-C++ (using mingw compiler) overwrites what I have created with a generic DEF that doesn't do any better.

    Now, my DLLs work great with C++.

    I am thinking, from one declaration above, that results in NO error of "cannot find DLL entry"...that this may be possible for VB to build a regular DLL without the DEF....I have read other postings elsewhere to suggest this.

    Again, I don't particularly care, as long as I can get this to work with VB.

    Any Dev-C++ regular DLL samples with a working DEF would be greatly appreciated...please don't send me VC++ stuff and say something like "...just change this and this..." because I am pretty tired of that trap.

    If I'm fustrated...its because I am. No offense to anyone...especially great programmers who can't write a tutorial to save their life. ;-)

    Regards,
    ChuckB

  5. #5

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    I'm making DLL with VC++ for implementation into VB. However, if anyone has figured out how to take a Dev-C++ 4.01 (mingw32 compiler) to create a DLL that works in VB...please, please let me know.
    I own VC++ but I like the look and feel of Dev-C++ much better.

    Regards,
    ChuckB

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Normally you'd want the extern "C" and __stdcall (or its Dev-C++ equivalent).

    Once you've compiled it and got an .obj file, you need to pass your own custom .def file to the linker. How you do that I have no idea, see your documentation Somehow there should be a compiler option to pass an option to the linker.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Since I don't have Dev-C++ I can't help you there.
    But the bad calling convention is because VB expects DLL functions to use the pascal (or stdcall) convention, which means that the called function removes the arguments from the stack.

    It is possible to go without the def file, but then you MUST use extern "C" and you have to find out the mangled name:
    a function with the name func1 gets mangled to
    _func1@n
    where n is the number of bytes in the parameter list.
    void func(short s, long l, char *str);
    is on a 16-bit system
    _func@8
    on a 32-bit system
    _func@10
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    CornedBee,
    Thanks for the lead. I did not realize that with func@n, that 'n' meant the number of bytes. Most examples I saw looked kind of like this:

    func1@1
    func2@2
    func3@3

    So, I ASSumed 'n' constituted some index in list.
    Let me give that a try.

    The calling convention error was significant because I supposed it mean my ealier and more dominate error "Bad DLL Entry" was corrected...but now I believe that error is checked after the 'bad calling convention'.

    I'll report back results.
    Regards,
    ChuckB

  9. #9
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Also, one thing you should not forget is that the vb IDE has a bug in it that will not allow you to call ur own dll files!!! You have to compile it to an exe and test it out. Compile with native code and the debug turned on. Then use ur vc++, devc++ whatever, to do the debugging!

    The reason for the bad dll calling convention in the vb ide is that you need to make an atl or com dll for vb to understand the dll well otherwise a bug in the ide will prevent it from gaining access... maybe because of the debug, i dont know. Its happened to me too many times. So dont forget to compile... its annoying but crusial.

    Hope that helps,
    MoMad the NoMad
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Uh, no, actually it worked perfectly for me without compiling using VB 6 and VC++ 6 (SP5).
    And VB CAN use non-COM DLLs.

    Maybe you mean using VB dlls in C++? (There was a discussion somewhere...)

    I could even start an uncompiled VB exe in the IDE and then jump to the C++ debugger for the DLL. The only problem is that when you click "stop debugging" in the C++ debugger VB is closed.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    No, im pretty sure of that. And i think i might even have an example of such thing...its stashed up somewhere on my code collection backup cds. I will post it later.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But I managed to do both things you said were impossible - and it's in a commercial app!
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi,
    I appreciate the dialog. I can do the following:

    1. Write DLL in Dev-CPP that can be read by another app in Dev-CPP.
    2. Write DLL in VC that can be read by VB.

    I cannot create DLL in Dev-CPP that will work with VB....that is where I still need input.

    Dev-CPP???

    My preference for Dev-CPP is that it is open source and I can use it to teach my 24 students C++ without incurring a significant cost by buying 24 licenses for VC++.

    I am working a Domino game project with son in Comm forum. He is writing Domino activeX control in VB...I was hoping to use Dev-CPP to write the AI engine as a DLL for the experience. I can still do that with VC++....just prefer Dev-CPP.

    Thanks,
    ChuckB

  14. #14
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    As long as the DLL uses __stdcall convention, then you can make a c++ dll that works with vb. Just make sure to define the functions as __stdcall so they dont get mangled by the c++ compiler.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The __stdcall doesn't prevent them from being mangled. The extern "C" tells the compiler to mangle in the C way instead of the C++ way. You cannot completly disable name mangling unless you have a compiler that follows the ELF specification.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi,
    I am digging into Day 17 of Teach Yourself VC++...Creating DLLs. Hopefully soon I will have what you guys are writing sorted out in my head.

    Then I can write a procedure for dummies on creating a DLL...steps 1 through whatever.

    Thanks,
    Chuck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width