-
Re: Dll function call problem - Same problem
I have exactly the same problem. My c-code:
__declspec(dllexport) int intarg(int intArg1)
{
return intArg1;
}
My VB-code:
Declare Function intarg Lib "testdll.dll" (ByVal intArg1 As Integer) As Integer
Sub runtestdll()
Dim intTest As Integer
intTest = 5
intTest = intarg(intTest)
MsgBox intTest
End Sub
This gives the error "Bad DLL calling convention". If I however declare the
function as if it doesn't have any parameters it does not give me an error.
Like this:
Declare Function intarg Lib "testdll.dll" () As Integer
Sub runtestdll()
Dim intTest As Integer
intTest = intarg()
MsgBox intTest
End Sub
It seems that the parameter in the c function isn't exported or something?
Does anyone have any idea how to solve this?
Greateful for any help.
/Fabian Fischer
"Pete Mitchell" <pmitchel@attachegroup.com> wrote:
>
>I keep getting the runtime error '49' "Bad DLL calling convention" error
message
>
>when calling a function in a dll from my VB program.
>It's C syntax is:
>long Julian_Date(char *szDate)
>
>Here is my Declaration in the General Decs of a form:
>Private Declare Function Julian_Date Lib "d:\Chariotts\qengine.dll" (ByVal
>
>sDate As String) As Long
>
>Here is the call to the function from a button click event:
>Private Sub Command1_Click()
> Dim retval As Long
> Dim sDate As String
>
> sDate = "19990625"
> retval = Julian_Date(sDate)
>
>End Sub
>
>I have also tried changing the function declaration to pass the parameter
>ByRef with the same result.
>
>I have successfully called this function from Visual FoxPro so I figured
>
>that the function is exposed and available.
>
>What am I doing wrong ????
>
>Thanks in advance.
>
-
Re: Dll function call problem - Same problem
I have exactly the same problem. My c-code:
__declspec(dllexport) int intarg(int intArg1)
{
return intArg1;
}
My VB-code:
Declare Function intarg Lib "testdll.dll" (ByVal intArg1 As Integer) As Integer
Sub runtestdll()
Dim intTest As Integer
intTest = 5
intTest = intarg(intTest)
MsgBox intTest
End Sub
This gives the error "Bad DLL calling convention". If I however declare the
function as if it doesn't have any parameters it does not give me an error.
Like this:
Declare Function intarg Lib "testdll.dll" () As Integer
Sub runtestdll()
Dim intTest As Integer
intTest = intarg()
MsgBox intTest
End Sub
It seems that the parameter in the c function isn't exported or something?
Does anyone have any idea how to solve this?
Greateful for any help.
/Fabian Fischer
"Pete Mitchell" <pmitchel@attachegroup.com> wrote:
>
>I keep getting the runtime error '49' "Bad DLL calling convention" error
message
>
>when calling a function in a dll from my VB program.
>It's C syntax is:
>long Julian_Date(char *szDate)
>
>Here is my Declaration in the General Decs of a form:
>Private Declare Function Julian_Date Lib "d:\Chariotts\qengine.dll" (ByVal
>
>sDate As String) As Long
>
>Here is the call to the function from a button click event:
>Private Sub Command1_Click()
> Dim retval As Long
> Dim sDate As String
>
> sDate = "19990625"
> retval = Julian_Date(sDate)
>
>End Sub
>
>I have also tried changing the function declaration to pass the parameter
>ByRef with the same result.
>
>I have successfully called this function from Visual FoxPro so I figured
>
>that the function is exposed and available.
>
>What am I doing wrong ????
>
>Thanks in advance.
>
-
Re: Dll function call problem - Same problem
Fabian,
>It seems that the parameter in the c function isn't exported or something?
>Does anyone have any idea how to solve this?
You have to use Standard Calling conventions, not C calling
conventions.
Get rid of the __declspec(dllexport), and add __stdcall
Then, you'll have to add a .DEF module and declare the function inside
of that module.
Everything should work fine then.
Ciao, Craig
-
Re: Dll function call problem - Same problem
Fabian,
>It seems that the parameter in the c function isn't exported or something?
>Does anyone have any idea how to solve this?
You have to use Standard Calling conventions, not C calling
conventions.
Get rid of the __declspec(dllexport), and add __stdcall
Then, you'll have to add a .DEF module and declare the function inside
of that module.
Everything should work fine then.
Ciao, Craig
-
Re: Dll function call problem - Same problem
Yep, consider __declspec(dllexport) as evil.
The dll function will work but you'll get error 49 (bad convention) when
it exits. You should always use the _stdcall /EXPORT combination for functions
in the dll that you want to call from VB.
I don't know if this affects programs written in other languages calling
those functions.
Ken
Craig Clearman <chclear@nospam.please> wrote:
>Fabian,
>
>>It seems that the parameter in the c function isn't exported or something?
>>Does anyone have any idea how to solve this?
>
>You have to use Standard Calling conventions, not C calling
>conventions.
>
>Get rid of the __declspec(dllexport), and add __stdcall
>
>Then, you'll have to add a .DEF module and declare the function inside
>of that module.
>
>Everything should work fine then.
>
>Ciao, Craig
>
-
Re: Dll function call problem - Same problem
Yep, consider __declspec(dllexport) as evil.
The dll function will work but you'll get error 49 (bad convention) when
it exits. You should always use the _stdcall /EXPORT combination for functions
in the dll that you want to call from VB.
I don't know if this affects programs written in other languages calling
those functions.
Ken
Craig Clearman <chclear@nospam.please> wrote:
>Fabian,
>
>>It seems that the parameter in the c function isn't exported or something?
>>Does anyone have any idea how to solve this?
>
>You have to use Standard Calling conventions, not C calling
>conventions.
>
>Get rid of the __declspec(dllexport), and add __stdcall
>
>Then, you'll have to add a .DEF module and declare the function inside
>of that module.
>
>Everything should work fine then.
>
>Ciao, Craig
>
-
Re: Dll function call problem - Same problem
Ken,
>Yep, consider __declspec(dllexport) as evil.
It's _cdecl (or rather any calling convention other than _stdcall)
that is "evil", not __declspec(dllexport). You *can* use
__declspec(dllexport) and still call the function from VB, if you
correctly combine it with _stdcall, but the name of the exported
function will be mangled. Using a DEF file instead gives you more
control over the name and/or the ordinal of the exported function.
Mattias
____________________________________________
Mattias Sjögren - mattiass @ hem.passagen.se
-
Re: Dll function call problem - Same problem
Ken,
>Yep, consider __declspec(dllexport) as evil.
It's _cdecl (or rather any calling convention other than _stdcall)
that is "evil", not __declspec(dllexport). You *can* use
__declspec(dllexport) and still call the function from VB, if you
correctly combine it with _stdcall, but the name of the exported
function will be mangled. Using a DEF file instead gives you more
control over the name and/or the ordinal of the exported function.
Mattias
____________________________________________
Mattias Sjögren - mattiass @ hem.passagen.se
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|