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
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
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…

856 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