ECS-L Home Automation and Security Archives
  learn more | view messages for this month | NetBloc® | terms of use | search

Google
 


  subject (prev) or (next) | time (prev) or (next) | author (prev) or (next) | view more subjects

Subject:
From:
Date:
Can anyone spot this guy's BASIC compile err ? (charity case :-))
Mark Gilmore
Wed, 20 Jan 1999 11:43:35 -0800
Wed, 20 Jan 1999 11:43:35 -0800
-- 
Mark Gilmore
Omnipotence (ECS Home Automation Software)
Voice:423-745-0026
FAX  :423-745-1714
omnip@usit.net
http://www.usit.com/omnip

Subject:
From:
Date:
Calling C DLL from Visual Basic
Mark Einhorn
Wed, 20 Jan 1999 10:35:22 -0600 (CST)

Why do I get the error    " Bad DLL calling convention" (described below
>from the Visual Basic help) when I run this Visual Basic program? The 3
paramaters in the C dll are defined as LPCSTR.  I believe I am using the
correct calling convention. So, I think it may be the way the DLL header
is constructed for languages other than C.

(NOTE: Attached Down  below is C code used to make the call to the DLL.)

Visual Basic Code:
Private Declare Function SOX Lib "E:\SAPI\SoundC\sox10dos\soxdll\sox.dll" (ByVal cmd
As String, ByVal outmess As String, ByVal errmess As String) As Variant

Dim a As String
Dim b As String
Dim c As String

a = "test"
b = String(513, " ") 'Create a buffer of 513
c = String(513, " ")  'Create a buffer of 513

SOX a, b, c


Bad DLL calling convention (Error 49)

Arguments passed to a dynamic-link library (DLL) routine must exactly match those expected
by the routine.
Calling conventions deal with number, type, and order of arguments. This
error has the following causes and solutions: 

·	Your program is calling a routine in a DLL that's being passed the wrong type of arguments.

Make sure all argument types agree with those specified in the declaration of the routine
you are calling.

·	Your program is calling a routine in a DLL that's being passed the wrong number of
arguments.

Make sure you are passing the same number of arguments indicated in the declaration
of the routine you are calling.

·	Your program is calling a routine in a DLL, but isn't using the StdCall calling convention.

If the DLL routine expects arguments by value, then make sure ByVal is specified for
those arguments in the declaration for the routine.

·	Your Declare statement includes CDecl.

The CDecl keyword applies only to the Macintosh.



C code used to call the DLL:
Here is the some code in C which calls the DLL:
#include	"sys.h"
#include	"ut_rf.h"
void		main(
I2		argc,
U1		*args[])
{
HANDLE		lbhnd = NULL;
BOOL		(*rtn)(LPCSTR, LPCSTR, LPCSTR);
static U1	out[513];
static U1	err[513];

lbhnd = LoadLibraryEx("SOX.DLL", (HANDLE)NULL, 0);
if (! lbhnd)
	W95_ERR("LL");
else
	{
	rtn = (int (__cdecl *)(LPCSTR, LPCSTR, LPCSTR))GetProcAddress(lbhnd, "SOX");
	if (! rtn)
		W95_ERR("GPA");
	else
		{
		(*rtn)("test", out, err);
		printf("out=%s\n", out);
		printf("err=%s\n", err);
		}
	}
if (err_) printf("%s\n", ERR_S());
}






=========================================
      Mark Einhorn                                 
      President, CyberBiz, Inc.               
      Chicago, Illinois USA                                                        
                   :
      mje@cyberbiz.com                     
      PH: 773-338-3755   Fax: 773-338-7567
=========================================



 Wed, 20 Jan 1999 10:35:22 -0600 (CST)

  subject (prev) or (next) | time (prev) or (next) | author (prev) or (next) | view more subjects




Services provided by [NetBloc]®! NetBloc Solutions Inc.
Terms of use. Indexing software (c) 1999 Lin-De, Inc
.