16bit->32bit C dll : bad dll calling convention 
Author Message
 16bit->32bit C dll : bad dll calling convention

i converted a 16bit c dll (VC1.51) to 32 bit C dll (VC4.0) and now when i call
it from 32 bit VBA i get an error message : bad dll calling convention. does
anyone know why??

the declare line is:

Declare function getfb Lib "FBD32.DLL" (ByVal mrid as double, ByValue op as    
             double) as double

jason new



Sun, 30 Sep 2001 03:00:00 GMT  
 16bit->32bit C dll : bad dll calling convention
Your declare code looks okay. From the help file:

[Public | Private] Declare Function name Lib "libname" [Alias "aliasname"]
[([arglist])] [As type]
                          Declare function  getfb Lib "FBD32.DLL" (ByVal mrid as
double, ByValue op as double) as double

Can you call the DLL form a 32  bit VC++ program and have it work all right?

Quote:

> i converted a 16bit c dll (VC1.51) to 32 bit C dll (VC4.0) and now when i call
> it from 32 bit VBA i get an error message : bad dll calling convention. does
> anyone know why??

> the declare line is:

> Declare function getfb Lib "FBD32.DLL" (ByVal mrid as double, ByValue op as
>              double) as double

> jason new



Sun, 30 Sep 2001 03:00:00 GMT  
 16bit->32bit C dll : bad dll calling convention
Your function must use the __stdcall calling convention, not the default
__C convention.  Since you don't show the C side, I can't say positively
that's what the problem is, but it's a very good bet.

--
     Jim Mack
     MicroDexterity, Inc

     http://www.microdexterity.com




Quote:
>i converted a 16bit c dll (VC1.51) to 32 bit C dll (VC4.0) and now when
i call
>it from 32 bit VBA i get an error message : bad dll calling convention.
does
>anyone know why??

>the declare line is:

>Declare function getfb Lib "FBD32.DLL" (ByVal mrid as double, ByValue
op as
>             double) as double

>jason new



Sun, 30 Sep 2001 03:00:00 GMT  
 16bit->32bit C dll : bad dll calling convention
thanx for your response.
Quote:

>Your function must use the __stdcall calling convention, not the default
>__C convention.  Since you don't show the C side, I can't say positively
>that's what the problem is, but it's a very good bet.

was is the __stdcalling convention?
i went thru the msdn and did the following:
i changed the export declartion from

double FAR Pascal _export getfb(double MRID,double OP)
 to
__declspec (dllexport) double getfb(double MRID,double OP)

 i also got rid of the WEP(windows exit program?) section and the Libmain(didnt
work with it in or out.). i also got rid of the DEF file as per msdn
documentation

is there something else i need to do?

the following is the c code:
#include <windows.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include "FBDLL.H" //nothing in this file
#include <stdio.h>
#include <string.h>

//      Prototypes
//__________________________________

//double FAR PASCAL _export getfb(double MRID,double OP);
__declspec(dllexport ) double getfb(double MRID,double OP);
//extern "C"__declspec( dllexport ) int MyFunc(long parm1);

//_________________________________
//      Initialize Library
//      when DLL is first called
//__________________________________
/*
int FAR PASCAL LibMain
(
        HANDLE hModule,
        WORD    wDataSeg,
        WORD    cbHeapSize,
        LPSTR   lpszCmdLine
)

{
//      Avoid warnings on unused formal parameters

        wDataSeg=wDataSeg;
        cbHeapSize=cbHeapSize;
        lpszCmdLine=lpszCmdLine;

//      hmodDLL=hModule;   //dll compile error

        return 1;

Quote:
}

//________________________________
//      WEP
//      C7 and QCWIN provide default WEP
//_________________________________

#if (_MSC_VER < 610)

int FAR PASCAL WEP(int fSystemExit);

//____________________________________

#pragma alloc_text(WEP_TEXT,WEP)

// for when DLL is unloaded
//__________________________

int FAR PASCAL WEP
(
        int fSystemExit
)
{
        //avoid warnings on unused formal parameters

        fSystemExit=fSystemExit;

        return 1;

Quote:
}

#endif   //C6

//extern "C"__declspec( dllexport ) int MyFunc(long parm1);

*/
//double FAR PASCAL __declspec(dllexport) getfb(double MRID,double OP)
__declspec (dllexport) double getfb(double MRID,double OP)

{
int i;
double fb,oparray[34],mm525[12],mm737[17],mm779[18],mm1023[24],mm1541[34];
....
return(fb)



Mon, 01 Oct 2001 03:00:00 GMT  
 16bit->32bit C dll : bad dll calling convention
forget it, it works now.

i changed to the _stdcall and i used the decorated name in the def file

seems to work

jason new



Mon, 01 Oct 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. 2 PRBS: Calling 16 bit DLL from VB5 and Bad DLL Calling Convention

2. Bad DLL calling convention VB-to-C DLL

3. C DLL (VC5) and Bad DLL Calling Convention

4. Bad DLL Calling Convention with CPUINF32.DLL

5. Possible answer to Err 49: Bad DLL calling convention

6. Run-time error '49': Bad DLL calling convention

7. Possible answer to Err 49: Bad DLL calling convention

8. Bad Dll Calling Convention???

9. VB Error: "Bad DLL Calling Convention"

10. Bad DLL calling convention (error 49)

11. "Bad DLL Calling Convention"

12. Error 49: Bad Dll Calling convention

 

 
Powered by phpBB® Forum Software