Solved

Calling CDecl funcitons in a DLL from VB+

Posted on 1998-01-13
3
618 Views
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...
Gutto
0
Comment
Question by:LMSuporte
  • 2
3 Comments
 

Author Comment

by:LMSuporte
ID: 1450814
Edited text of question
0
 
LVL 4

Expert Comment

by:rantanen
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.
0
 
LVL 4

Accepted Solution

by:
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

http://www.powerbasic.com/pbdll/pbdllwht.html

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now