Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: "bad dll calling convention" error occurs while calling function which is in a d

202| Thu, 07 Feb 2008 20:35:00 GMT| rizwanrafique| Comments (14)
Error is Runtime Error '49': Bad Dll calling concention

fname = "c:\file.wav"
rc = writeWave(fname) 'on this line error is occuring

writeWave file function is defined in a DLL and there its header is like this:

int writeWave(char *fname);

Any Idea?

Keywords & Tags: bad, dll, calling, convention, error, occurs, function, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/169/
 
«« Prev - Next »» 14 helpful answers below.
i think u have to change the *char to LPSTR
this site will give u better idea.

MSDN (http://support.microsoft.com/default.aspx?scid=KB;EN-US;q153586)

dinesh123 | Sat, 10 Nov 2007 00:13:00 GMT |

in the Msdn example you read also this:

Private Sub Form_Click()
ret& = PassStrStdCall("hello")
Print ret&
End Sub

Note: do not use "&" to say "Long", but
change the above to:

Private Sub Form_Click()
dim ret as Long
ret = PassStrStdCall("hello")
Print ret
End Sub

cimperiali | Sat, 10 Nov 2007 00:14:00 GMT |

Yes dinesh123 I already changed it :) but still error exists and i have read the description given in MSDN for this error but nothing happened. still there

rizwanrafique | Sat, 10 Nov 2007 00:15:00 GMT |

Make sure your DECLARE statement in VB use ByVal.

-Cool Bizs

coolbiz | Sat, 10 Nov 2007 00:16:00 GMT |

Yes i am but still problem exists.
Here is another line from my same application consisting the same problem.

Following is the function call from VB:

setRecordingStatus (False)

And the declaration in a module in the same project in VB:

Declare Sub setRecordingStatus Lib "recorder.dll" (ByVal rs As Boolean)

Now, declaration and definition in DLL:

//declaraion
void setRecordingStatus(bool);

//definition
void setRecordingStatus(bool rs)
{
recordingStopped = rs;
}

Isnt it bad?

rizwanrafique | Sat, 10 Nov 2007 00:17:00 GMT |

Call setRecordingStatus(False)
or
setRecordingStatus False

cimperiali | Sat, 10 Nov 2007 00:18:00 GMT |

No!
doesnt work, i have tried it :(
anyway it's leaving time now in Pakistan so see ya people tomorrow with all the problems :)
lets see if i have to spend time on it tomorrow or not

rizwanrafique | Sat, 10 Nov 2007 00:19:00 GMT |

hello friends.. this is what i did for the same..

change the C declaration of the function in the DLL from __cdecl to __stdcall

while compiling the functions with __stdcall calling convention the C compiler changes the name of the function to its internal decorated name .

Use that decorated name in the declaration of the function in Visual basic by using alias

there is a convention of C compiler to create decorated names.

for that convention refer to MSDN

if it doesn't work mail me at deepak_garg...rediffmail.com

(also let me know whether the problem is coming when run from the Visual basic IDE or from the EXE of the application)

ascom | Sat, 10 Nov 2007 00:20:00 GMT |

Yes! the problem is solved but I dont know why it did work. Because I check MSDN and there nothing like this is written. Its just about different calling convention for emtying the stack, bla bla

Would you please explain some more?

It did problem with both, executing from IDE and compiling as EXE and then executing sepately!!

rizwanrafique | Sat, 10 Nov 2007 00:21:00 GMT |

u didn't write whether u used decorated names or not...& what is not mentioned in the MSDN...the information about calling conventions or about decorated names for __stdcall calling convention??...i got all the information from MSDN itself.. yes i agree that all the information is not consolidated there ...

ascom | Sat, 10 Nov 2007 00:22:00 GMT |

Hmm
I've read it again :) on MSDN
From MSDN:

Name-decoration convention:
An underscore (_) is prefixed to the name. The name is followed by the at sign (...) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func...12

I understood the name decoration convention but I dont understand how it effect my program because I can't see it. And I didn't use decorated names, just same as before.

rizwanrafique | Sat, 10 Nov 2007 00:23:00 GMT |

its strange that ur program worked without using decorated name of the function as alias...the name C exports is decorated name & YOUR fuction name wud not be there in the list of exported functions... u specify the Declare statement in VB application & it searches for the function name in the dll...if function name is not found.. error comes.. can't find entry point in the dll.. i forgot the error number...what i feel if u are not using decorated names than this error shud have come... any way if it worked that means i have to work on it more...

ascom | Sat, 10 Nov 2007 00:24:00 GMT |

This is what I've declared in VB module

Declare Sub setRecordingStatus Lib "recorder.dll" (ByVal rs As Boolean)

And i've seen the dll in depands.exe, it shows me the same names as before. i.e., no decorated names at all!

rizwanrafique | Sat, 10 Nov 2007 00:25:00 GMT |

and dependency walker shows me decorated name for my dll:D
anyway.. enjoy without decoration

ascom | Sat, 10 Nov 2007 00:26:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories