?
Solved

VB and VC++

Posted on 1998-11-09
6
Medium Priority
?
323 Views
Last Modified: 2010-04-30
hi,
I am currently trying out the following:
1) create a simple push button (command1) on form1
2) have a simple function callback in VC++ and build as dll
3) try to import the dll using Project->Reference so that when command1.click, i can call the VC++ function. however, there's an error when i try to add the dll using Project->References.

Please advise on the steps necessary to call the VC++ functions from my VB forms.

thanks,
hui
0
Comment
Question by:andreat
[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
  • 4
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 40 total points
ID: 1443900
VB project references are for ActiveX objects. If you are making a standard DLL, use the Declare keyword in VB.
0
 
LVL 4

Expert Comment

by:tomook
ID: 1443901
Post your C function prototype and I can help you with the Declare syntax.
0
 

Author Comment

by:andreat
ID: 1443902
hi tomook,
I've tried playing around on my own based on the VB and VC++ online help and this is what i've done:

1) create a Win32 dll type project. at Project->Settings->Link, check Generate Mapfile

2) create a simple function
#include <iostream.h>
#include "testout.h"

void FuncCall(void)
{
      cout<<"hello"<<endl;
}

3) testout.h contains the following lines:
#define DllExport __declspec( dllexport )
void DllExport __cdecl FuncCall(void);

4) create a new VB project with a push button (command1)

5) create a new module with the following line :
Declare Sub FuncCall Lib "c:\project\vb\testout.dll" ()

6) add the following function callback
Private Sub Command1_Click()
Call FuncCall
End Sub

When I run the project, I have the following error message:
"Run-time error 453
Can't find DLL entry point FuncCall in c:\project\vb\testout.dll"

Please advise.
Thanks.
hui


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:tomook
ID: 1443903
First, VB likes things better as functions. Try redefining as
long FuncCall(void)
and
Declare Function FuncCall Lib "c:\project\vb\testout.dll" () As Long

Second, you will need to write a .DEF file. To find out what to put in it, create a link map in C++. Your will probably find your function will be "adorned" with extra characters. This can be mapped in the .DEF file.
0
 

Author Comment

by:andreat
ID: 1443904
hi
I will try out your advice.
The reason why I didn't create a .DEF file was because the help notes state that if I used __declspec(dllexport), I don't need to.
Also, do I have to check the VC++ Project->Settings->Link, Generate Mapfile option? what is it used for?

thanks,
hui
0
 
LVL 4

Expert Comment

by:tomook
ID: 1443905
I am afraid with VB you always need a .DEF file. I have never had it work correctly yet between VC++ and VB without one.

The map will tell you what you need to put in the .DEF file. It will show you the decorated name which you will expose as a simple name.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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