|
-
Aug 13th, 2002, 09:18 AM
#1
Thread Starter
Addicted Member
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
-
Aug 13th, 2002, 11:49 AM
#2
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.
-
Aug 13th, 2002, 12:38 PM
#3
Thread Starter
Addicted Member
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
-
Aug 13th, 2002, 12:52 PM
#4
Thread Starter
Addicted Member
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
-
Aug 14th, 2002, 01:08 PM
#5
Thread Starter
Addicted Member
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
-
Aug 14th, 2002, 02:17 PM
#6
Monday Morning Lunatic
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
-
Aug 19th, 2002, 07:08 AM
#7
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.
-
Aug 19th, 2002, 07:46 PM
#8
Thread Starter
Addicted Member
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
-
Aug 20th, 2002, 02:00 AM
#9
Fanatic Member
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
-
Aug 21st, 2002, 05:06 AM
#10
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.
-
Aug 21st, 2002, 06:15 AM
#11
Fanatic Member
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.
-
Aug 21st, 2002, 09:11 AM
#12
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.
-
Aug 21st, 2002, 10:48 AM
#13
Thread Starter
Addicted Member
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
-
Aug 21st, 2002, 03:15 PM
#14
Fanatic Member
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.
-
Aug 22nd, 2002, 05:25 AM
#15
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.
-
Aug 22nd, 2002, 12:38 PM
#16
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|