• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

Creating a DLL for Visual Basic 6

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
Grendies
Asked:
Grendies
  • 9
  • 7
  • 3
1 Solution
 
mrwad99Commented:
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
 
mrwad99Commented:
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
 
GrendiesAuthor Commented:
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
mrwad99Commented:
0
 
GrendiesAuthor Commented:
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
 
mrwad99Commented:
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
 
mrwad99Commented:
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
 
GrendiesAuthor Commented:
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
 
GrendiesAuthor Commented:
urrm, how do i post link questions, (i sux, lol)

cant find the FAQ =/
0
 
mrwad99Commented:
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
 
GrendiesAuthor Commented:
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
 
GrendiesAuthor Commented:
opps, i mean the one included with FDSTAlk.dll
0
 
drichardsCommented:
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
 
mrwad99Commented:
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
 
drichardsCommented:
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
 
GrendiesAuthor Commented:
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
 
GrendiesAuthor Commented:
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
 
drichardsCommented:
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
 
GrendiesAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now