Link to home
Start Free TrialLog in
Avatar of cheater512
cheater512

asked on

C++ DLL not working in VB

I have made a DLL in Borland C++ Builder 3.0 (dont laugh) and I am trying to use it in VB.
This is for all you C++ and VB gurus. The function that i want to call is this:

char WINAPI _stdcall SHA1(char FileName)
{
      if(sha1_file(FileName,d,0) == 0){
            fhash(d, out);
            return out;
      }else{
            return "00000000000000000000";
      }
}

I know that the function works fine but when i put it in to VB with this code:
Private Declare Function SHA1 Lib "sha1vb" (ByVal FileName As String) As String

I get the error message: "453 Can't find entry point  SHA1 in sha1vb"
The dll is under C:\ so that shouldnt be the reason.
Please help.
Avatar of Member_2_1201329
Member_2_1201329

Hi cheater 512,
from the error message you can see that finding the dll is not the problem. I think the problem is that VB can't find your function within the dll because you did not make it public. Try using the public keyword in your dll. VB should the be able to find your function.

Hope this helps,
Christoph
Avatar of cheater512

ASKER

Didnt help. It now looks like this:

extern “C” __declspec(dllexport) char SHA1(char);
//---------------------------------------------------------------------------
public char WINAPI _stdcall SHA1(char FileName)
{
      if(sha1_file(FileName,d,0) == 0){
            fhash(d, out);
            return out;
      }else{
            return "00000000000000000000";
      }
}
Good Cheater512,

I never used the Borland compiler (I used Visual C++).

See also if you have a file .def

In Visual C++ you should add in the .def the function you export.
This is a sample Visual C++ .DEF file

LIBRARY ADDUSER
DESCRIPTION 'Esempio di DLL per Visual Basic'

EXPORTS
      AddUser @1
      RollBackUser @2

Hope is usefull,

Max
There is no .def file with Borland.
You probably did this already, but I'm I'll ask nevertheless:

Did you register your dll?

It is not required to register the DLL!!!

You forgot to add the __stdcall !!!

Bye,

Max
As an example,

your code should be:

extern “C” __declspec(dllexport) __stdcall char SHA1(char);
//---------------------------------------------------------------------------
__declspec(dllexport) public char  __stdcall  SHA1(char FileName)
{
     if(sha1_file(FileName,d,0) == 0){
          fhash(d, out);
          return out;
     }else{
          return "00000000000000000000";
     }
}

Hope this clarify,

Max
I get the same error with __stdcall added.
Hi,

just in case, are you sure it is a DLL and not an ActiveX DLL?

Bye,

Max
Hi,

another thing come tomy mind.

I see your declaration is as follow:

Private Declare Function SHA1 Lib "sha1vb" (ByVal FileName As String) As String

Well,

if you have different copies of that file in your path, than this could be the problem.

Try to specify the path to your last build like:

Private Declare Function SHA1 Lib "d:\Prog\C++\sha1\debug\sha1vb.dll" (ByVal FileName As String) As String


Bye,

Max
That didnt work either. Same error.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

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