Solved

VB and VC++

Posted on 1998-11-09
6
283 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now