Solved

VB and VC++

Posted on 1998-11-09
6
316 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 20 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 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