Solved

Creating a DLL for Visual Basic 6

Posted on 2004-08-22
19
460 Views
Last Modified: 2013-11-25
hello, i wasnt sure wether this should go into C, C++,Visual C++.NET or VB6 but i had a guess :)

well anyway, i am creating a DLL for use in VB6, when i compile the DLL, and then use it in VB6, when i try to call the DLL i get, Run Time Error Cannont Locate DLL Entry Point Connect

i think its the way i have exported the functions, so i was just wondering if anyone could take a look at it

-Thanks! :)

http://www.aohost.co.uk/RenFDSComm.zip
0
Comment
Question by:Grendies
  • 9
  • 7
  • 3
19 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 11864261
You are not defining FDSTALK_EXPORTS anywhere, therefore your functions are never being exported.

#ifdef FDSTALK_EXPORTS
#define FDSTALK_API __declspec(dllexport)
#else
#define FDSTALK_API __declspec(dllimport)
#endif

#define FDSTALK_EXPORTS somewhere in the .cpp file for these functions.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11864315
In fact, having looked harder, it is tough to see what you are trying to do here.  What functions are you trying to export ?  At the moment you are not exporting anything (view the DLL with dependency viewer, part of VC++ tools)
0
 

Author Comment

by:Grendies
ID: 11864810
me and a friend are making this DLL together (which is why it says made by one person in another and made by someone else in another part of it)

the DLL is called RenFDSComm.dll, there is this dll called FDSTalk.dll that is used to communicate with the C&C Renegade FDS, unfortunetly, due to the way one of the functions returns a value (VB6 error) it will crash when you call the function

so we made this DLL which calls the functions in FDSTalk.dll and has the return values in a way that does not crash VB6

basically im trying to export every function in RenFDSComm.cpp

Connect
fdsmsg
Disconnect
and version
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11864999
0
 

Author Comment

by:Grendies
ID: 11865080
assumeing that is called the same way as RenFDSComm:

Private Declare Function Connect Lib "EE_DLL.dll" (ByVal lport As Integer, ByVal rpass As String) As Boolean
Private Declare Function fdsmsg2 Lib "EE_DLL.dll" Alias "fdsmsg" (ByVal msg As String, ByVal ip As Long, ByVal rpass As String, ByVal rport As Integer) As String
Private Declare Sub Disconnect Lib "EE_DLL.dll" ()

Run Time Error '453':

Can't find DLL entry point Connect in EE_DLL.dll
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11865135
Right well I am not hot on the way DLLs are used in VB but I can say that if you tried code in C++ using that DLL then it would work.  What you were doing before was not exporting any functions.  I opened your DLL up in dependency viewer, and when compared with the one above you can see that you were not actually exporting the functions you need.

http://homepage.ntlworld.com/d.billingham/EE_DLL.jpg

http://homepage.ntlworld.com/d.billingham/RenFDSComm.jpg

Try doing what you want in C++.  You must be doing something wrong in VB.  You could post a link question to this in the VB area I suppose, but I the DLL issue is now sorted.  It is just using it in VB that is the problem.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11865172
Have you done the equivalent in VC++ of linking with the .lib file ?  i.e. have you referenced this DLL in your VB code at all ?
0
 

Author Comment

by:Grendies
ID: 11865196
thank you, could you post the source code for EE_DLL.dll so i can take a look at what i was doing wrong and edit it at a later time please, thanks


ok, doing now :)


you dont need the lib file when you use a DLL in VB6, you just need the DLL name inside lib "<dll name>"
0
 

Author Comment

by:Grendies
ID: 11865215
urrm, how do i post link questions, (i sux, lol)

cant find the FAQ =/
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 19

Expert Comment

by:mrwad99
ID: 11865275
You need to change the header file to be like this:

#ifndef _FDSTALK_H
#define _FDSTALK_H

#ifdef FDSTALK_EXPORTS
#define FDSTALK_API __declspec(dllexport)
#else
#define FDSTALK_API __declspec(dllimport)
#endif

//Now its also posible to use the dll in MS Visual Basic and Borland Delphi.
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
      
      // You need to declare the functions you want to export here in the header file !

      FDSTALK_API bool _stdcall Connect(unsigned int lport,char *rpass);
      FDSTALK_API void _stdcall Disconnect(void);
      FDSTALK_API char* _stdcall fdsmsg(char *msg,unsigned long ip,char *rpass,unsigned int rport);
      FDSTALK_API char* _stdcall version(void);

      bool _stdcall Init(short port, char *password); // <-----------POINT 1
      void _stdcall Get_Response(char *&response);
      void _stdcall Shutdown (void);
      void _stdcall Send_Message(char *text, long ip, short port);
      void _stdcall Service(void);

}

#endif //_FDSTALK_H

Regarding point 1 as above, normally you would have some sort of header file that would be distributed with the DLL you wished to use; this would save you having to declare the functions locally just to get the compiler to see them.  I suppose this is one way of doing it differently though..

Also add

#define FDSTALK_EXPORTS

to your corresponding .cpp file.

Regarding link questions, just post a 20 point question, stating something like

"Title:  Link question: Problem with custom C DLL

Please participate here if you can:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21102669.html

Please do *not* post at this question here !"

HTH
0
 

Author Comment

by:Grendies
ID: 11865453
FDSTalk.h is the header file that was included with the DLL so that you can use it in a C program

shall i still edit it? =/
0
 

Author Comment

by:Grendies
ID: 11865473
opps, i mean the one included with FDSTAlk.dll
0
 
LVL 19

Accepted Solution

by:
drichards earned 125 total points
ID: 11867221
I have had difficulty in the past using '__declspec(dllexport)' to export functions that I want to use from VB.  Try using a def file to export the dll functions:

file 'RenFDSComm.def':

EXPORTS
  Connect
  Disconnect
  fdsmsg
  version


Then in project settings/properties say you are using a def file.  In VS .NET, it's in the input page in linker properties as "Module Definition File".  I forget where it is in VC6 if that's what you are using.  You also shouldn't need both extern"C" and __stdcall in the C++.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11867954
If you want to export the functions that you have mentioned then you need to edit the header file as I have mentioned.  As it was it was simply not exporting anything.
0
 
LVL 19

Expert Comment

by:drichards
ID: 11868183
If the dll is to be used only with VB, then you really only need:

    #define FDSTALK_API __declspec(dllexport)

as the header is not used for anything after the dll is built.  In fact, if all you've got in the header is function declarations, you probably don't need it at all.

The def file seems (to me) to be more reliable for exporting things for use by VB, though I can't imagine why.  With __declspec(dllexport), the functions are sometimes still not found by VB.

In Visual Studio .NET, right click on the project and say Add->"Add New Item..." and select "Module-Definition File (.def)" and it will add the necessary settings and also automatically export global functions.  Then recompile.  
0
 

Author Comment

by:Grendies
ID: 11868422
ok, thanks to drichards, it "appears" to be working

thanks! :)

ill have a fidde around with it to make sure its working 100% before accepting :)
0
 

Author Comment

by:Grendies
ID: 11868540
ok, i dont know if this is the DLL exporting problem, but although Connect works fine, fdsmsg does not seem to send the message to the FDS, any ideas =/
0
 
LVL 19

Expert Comment

by:drichards
ID: 11870565
At this point you should be able to debug the code.  In the dll project, go to the debugging settings and set the VB6 executable as the program to run for debugging.  You can set breakpoints in the C++ and see what is going on.
0
 

Author Comment

by:Grendies
ID: 11870897
ok, as i know the DLL is now working, its a problem in my code but you answered the question, ill accept :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now