Solved

VB and VC++

Posted on 1998-11-09
6
293 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

832 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