Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 5th, 2005, 11:54 AM
gjc gjc is offline
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using DLLs in VB 6

I whish to use a DLL I have created in VC++ so I have put the DLL in my system32 directory and declared the function I whish to use as follows:

Private Declare Function testFunc Lib _
"CalibrationDLL" (num As Integer) As Integer

the prototype in the DLL is:

extern "C" {
    int DLLDIR testFunc(int Num);
}

I then call the function in the code like this:

testResult = testFunc(1)

However, this throws and a run time error of:

Bad DLL calling convention.

What have I missed?

Cheers

Reply With Quote
  #2 (permalink)  
Old September 6th, 2005, 01:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is name decoration, that is you have to tell the compiler that the names of the methods should be left "as is", something like:

__declspec(dllexport) int testFunc(int Num)
{
}

and because you want to pass parameters to the methods, do not forget to generate the .def file.
Marco
Reply With Quote
  #3 (permalink)  
Old September 7th, 2005, 03:47 AM
gjc gjc is offline
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's what the DLLDIR macro does. the problem was that I needed to add__stdcall in front of the the function within the DLL.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use two dlls with same name but prakashrams ASP.NET 1.0 and 1.1 Basics 1 November 29th, 2006 11:26 AM
Making DLLs in VB.NET loganscott2000 VB.NET 2002/2003 Basics 2 April 10th, 2005 04:40 PM
Strong name to msinet wrapper dlls vb.net rameshu007 Classic ASP XML 0 July 13th, 2004 06:07 AM
Using VB 6.0 DLLs in .Net ECrawford ASP.NET 1.0 and 1.1 Basics 4 June 29th, 2004 07:25 AM
Help with using DLLs in VB vb_programmer Beginning VB 6 2 September 23rd, 2003 05:39 PM



All times are GMT -4. The time now is 08:30 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.