Link to home
Start Free TrialLog in
Avatar of Grendies
Grendies

asked on

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
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
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)
Avatar of Grendies
Grendies

ASKER

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
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
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.
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 ?
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>"
urrm, how do i post link questions, (i sux, lol)

cant find the FAQ =/
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:
https://www.experts-exchange.com/questions/21102669/Creating-a-DLL-for-Visual-Basic-6.html

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

HTH
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? =/
opps, i mean the one included with FDSTAlk.dll
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.  
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 :)
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 =/
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.
ok, as i know the DLL is now working, its a problem in my code but you answered the question, ill accept :)