Solved

C++ DLL not working in VB

Posted on 2003-11-12
15
299 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:cheater512
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
15 Comments
 
LVL 1

Expert Comment

by:ChristophMurczek
ID: 9737844
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
0
 

Author Comment

by:cheater512
ID: 9737884
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";
      }
}
0
 
LVL 2

Expert Comment

by:MaxPol
ID: 9738411
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
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:cheater512
ID: 9738472
There is no .def file with Borland.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9739158
0
 
LVL 1

Expert Comment

by:ChristophMurczek
ID: 9739171
You probably did this already, but I'm I'll ask nevertheless:

Did you register your dll?

0
 
LVL 2

Expert Comment

by:MaxPol
ID: 9739256
It is not required to register the DLL!!!

You forgot to add the __stdcall !!!

Bye,

Max
0
 
LVL 2

Expert Comment

by:MaxPol
ID: 9739295
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
0
 

Author Comment

by:cheater512
ID: 9742801
I get the same error with __stdcall added.
0
 
LVL 2

Expert Comment

by:MaxPol
ID: 9746472
Hi,

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

Bye,

Max
0
 
LVL 2

Expert Comment

by:MaxPol
ID: 9746534
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
0
 

Author Comment

by:cheater512
ID: 9753494
That didnt work either. Same error.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10191183
PAQed, with points refunded (75)

Computer101
E-E Admin
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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