Can I use this DLL in VB6 ?

BarryTang
BarryTang used Ask the Experts™
on
I have a DLL written by VC++ 6.0 and some related documents as follows

    A thisDLL.h file
    A thisDLL LIB file
    A thisDLL.dll file

It has no problem to call a function from thisDLL in VC++ as follows

#include "thisDLL.h"

int main()
{
     func1(my arguments...);
     return 0;
}

However, when I use it VB6 by following code :

Private Declare Function func1 Lib "thisDLL.dll" (the arguments declaration)
Private Sub Form_Load()
    call func1(my arguments...);
End Sub

It returns :
  Can't find DLL entry point func1 in thisDLL.dll

Is thisDLL can be used in VB6 or not ?

Actually I am not familiar with DLL calling process and know little about VC++.
Does anybody know how to fix my problem or give some hits for me about it.
Thank you

Barry

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
is "thisDLL.dll" registered with windows?

first locate where "regsrv32.exe" is and put thisDLL.dll in the same folder as it, then do the following:

start->run->regsrv32 thisDLL.dll
also, thisDLL.dll MUST be a COM DLL, and that takes some special coding in how the Exports are setup in the C++ code.

Not all C++ DLLS are automatically COM-compatible.  And a DLL MUST be COM compatible, to be registered.

you may need to treat the DLL like an API, and EXPLICITLY DECLARE the calling sequence.

Commented:
Okay to use a c++ dll in vb you have to do a couple things. One add a .DEF file to your c++ project, then you have to add something similar to

Library PROJECTNAME
Description "DESCRIPTION HERE"
EXPORTS
     FuncName   @1
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
    FuncName2  @2

and so forth

then to use it in vb you have to do something like

Private Declare Function Func1 Lib "YOURDLL" (ByVal Whatever as whatever)


that should let you use your dll in vb

Author

Commented:
Hello everybody :

When I try to register this DLL, it returns message as follows :

   thisDLL.dll was loaded, but the DllRegisterServer entry point was not found. This file can not be registered

So this may not be a COM DLL, right ?

Is there a way to solve this problem, actually I don't have the source code of the DLL so that I cannot do modification as List244 suggest !

Barry

Commented:
then, the dll should work fine.

use

Private Declare Function FUNCNAMEHERE lib "LIBRARY" (byval STuff as stuff)

but you have to know its function names and what it wants you to give it ie: Byval Stuff as stuff ect.

Author

Commented:
List244 :

I still don't know what is the difference between

Private Declare Function FUNCNAMEHERE lib "LIBRARY" (byval STuff as stuff)

and your previous one :

Private Declare Function Func1 Lib "YOURDLL" (ByVal Whatever as whatever)

Actually in my example, my 3 files are
   A thisDLL.h file
   A thisDLL LIB file
   A thisDLL.dll file
so the library name and dll name are the same

Actually I know the argument declarations : (ByVal ....)
and I try

Private Declare Function func1 Lib "thisDLL.dll"
or
Private Declare Function func1 Lib "thisDLL"

But both gives similiar error message !

Would you kindly explain it in a little more details since I only know a little about using DLL ?

Barry

Commented:
Try this:
Private Declare Function Function1 Lib "C:\Mydll.dll" ()

''' ASSUMING its actually in C:\... ect...

Or if you dont want to type in "c:\..." then you have to register the dll and then you should be able to do

Private Declare Function Function1 Lib "mydll" ()

Author

Commented:
List244 :
The result still the same when I use full path in the declaration !
Barry

Commented:
Okay Open the dll with the dependency viewer comes with
visualstudio, if you dont have that then you can download
a free version at:

http://www.dependencywalker.com

Open  the dll with this

Now if it shows the functions like

Func1
Func2

then it will work if it shows you weird symbols
then its lacking the .def file i mentioned before.
And tthe dll will not work in your vb project.

Thhough from the error it seems you may have the wrong function name, check what you have typed with what the dependency walker shows, the dependency walker however, WILL NOT show you what the function wants you will need to know that, but it will tell you the function names.

Now when you redeclare it try

Private Declare Function FUNCNAMEHERE lib "LIBRARY" (byval STuff as stuff)

and still give it the full path remember to include .dll so
"C:\Mydll.dll"

If it still errors please paste your highlighted line (the one that errors) as well as the error message here in a comment

Author

Commented:
List244 :

When I view the DLL with the dependency walker. I find that the function column display as follows :

    ?func1@@YAHPAD00H@Z

and the entry point state : 0x00003400

It is difference when I view other windows DLL such as user32.dll, the function name will not consist of strange character like '?','@',....

So, is this fcuntion : func1 not export to use.

Barry

Commented:
Okay thats what I was guessing. As far as I know you can not use that dll, i believe that means only the program that was compiled with that can use it, but im new to c++ and could be wrong. Though i dont believe you can use that in vb either way, in order for it to work with vb it should show a normal name no weird characters like that one did. Sorry, but i can't help you with using that dll.
BarryTang,
You have 17 opened questions as of this date.  
I will be posting in each of these questions.  
Please take care of your opened questions older than 30 days by clicking on your logon name link and looking for UnlockedQ or using the links I am providing below.  
Please finalize these within 72 hours or I will ask administration to look into your account at that point.  If you have questions, please ask and I will provide assistance.  

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20187331.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20133725.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20088012.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20083509.html
http://www.experts-exchange.com/Miscellaneous/Games/Q_20382035.html
http://www.experts-exchange.com/Programming/Game_Development/Q_20382294.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20534626.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20521771.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20515842.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20513575.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20493221.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20436510.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20399960.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20395868.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20375410.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20373966.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20372811.html

Thank you.
Administrative Action - PAQ'd and points NOT refunded.

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial