Calling CDecl funcitons in a DLL from VB+

Posted on 1998-01-13
Last Modified: 2008-02-01
     We would like to call DLL functions from a dll written in C Laguage. We all know that it is ok to do so in VB if the dll use standart declarations, but we have a problem here. The dll we want to call the function from, is entire wirtten using the C_Declare, what turns impossible(?!?) to call them.
      In order to avoid to use all those non-professional OCXs and VBXs and other Computer Telephony toolkits, we would like to call the Dialogic boards directly throu their dll, using their API. Using their dlls directly we will be able to save about 90% of memory and also we will be able to use threads.
      We have all the documentation to convert the *.H files to *.bas files. For exemple:      

            -in the *.h file we have:
            extern int dx_open( const char *namep, int oflags );

            -what becomes a *.bas file in VB5:
            declare function dx_open& lib "libdxxmt.dll" (byval char as string, byval oflags as long)

      The problem is that we will get a"Bad DLL calling convention" anyway. The DLL is is not acessible from VB becuse it is expecting a "standart declaration".
      We have been searching the web and asking the PROs, and it seems that we would have to either re-write the dll using standart declaration (which is  impossible since it is how the toolkit developers makes money) or write a "Wrapper DLL" to translate the calls.

The DLL vendor told me that it's necessary to write a "wrapper" DLL in C
language to translate the calls.

We would like to know if there is a work around, and how can we write a multithreaded wrapper dll without the original dll source code..

I Hope this helps, and I hope someone helps me!
Thanx in advance...
Question by:LMSuporte
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
  • 2

Author Comment

ID: 1450814
Edited text of question

Expert Comment

ID: 1450815
That is true, you can't do it without a wrapper DLL.

VB 4.0 had a bug which allowed the EXE version to call _cdecl declared functions, even if in IDE mode generated the error you mentioned. I don't know if VB 5.0 still has this bug - anyway you shouldn't trust on bugs :-)

To get started, lookup following MS Knowledge Base Article

How to Call C Functions That Use the _cdecl Calling Convention

Last reviewed: July 16, 1996
Article ID: Q153586

It is not very helpful, but just confirms what you have been told.

Accepted Solution

rantanen earned 200 total points
ID: 1450816
I just forgot ... you can do these kind of calls in Basic ... not in VB, in PB/DLL. It can use CDECL calling convention, so you can write your wrapper DLLs in PB/DLL or you can write most of your app in it and only create user interface in VB.

Check out at

I am making this an answer ... if you think you can get a better one from this forum, please feel free to reject it.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

733 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