Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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

  #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
  #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.



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





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