|
-
Sep 29th, 2000, 02:59 PM
#1
Thread Starter
Frenzied Member
I have a problem when i call the dll from VB.The message box appears but after i click ok i get the error message "bad dll calling convention".How can i solve this.
The Dll code
Code:
#include "stdafx.h"
void car(HWND h)
{
MessageBox(h,"OK","KO",MB_OK);
}
Def File
Code:
LIBRARY "brisi.DLL"
EXPORTS
car @2
And in VB a declare the function and call it:
Code:
Public Declare Sub car Lib "brisi.dll" (ByVal h As Long)
car Form1.hWnd
-
Sep 29th, 2000, 05:04 PM
#2
Monday Morning Lunatic
Try using:
Code:
#include "stdafx.h"
void __declspec(dllexport) car(HWND h)
{
MessageBox(h,"OK","KO",MB_OK);
}
for your code, and
Code:
LIBRARY "brisi.DLL"
EXPORTS
car
for your .def file.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 23rd, 2000, 11:09 AM
#3
Hyperactive Member
i get bad calling convention to dll
If i dont pass a parameter to a function dll in c++ a can get a return from it. if i do this
extern "C" __declspec( dllexport ) long returnNothing(long nDays)
{
return nDays;
}
i get bad dll calling convention.
any help heres the declare.
Declare Function returnNothing Lib "D:\DEVELOP\ALL16_32\myproj\Debug\myproj.dll" (ByVal nDays As Long) As Long
-
Nov 23rd, 2000, 12:02 PM
#4
Hyperactive Member
-
Nov 23rd, 2000, 01:19 PM
#5
Monday Morning Lunatic
Code:
extern "C" __stdcall __declspec(dllexport) long returnNothing(long nDays) {
return nDays;
}
The __stdcall may need to go after the __declspec.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 24th, 2000, 06:30 PM
#6
Hyperactive Member
extern "C" void __stdcall car(HWND h)
{
//code
}
will work. the extern "C" tells the compiler to do some name mangling thing so VB can understand it, and __stdcall means the func will clear up the stack afterwards, which VB requires.
def file:
LIBRARY "yourdll.dll"
EXPORTS
car
buzzwords are the language of fools
-
Nov 27th, 2000, 05:42 AM
#7
Hyperactive Member
here it is
extern "C" int __declspec(dllexport) CALLBACK returnNothing (int nDays)
{
return nDays;
}
vb:
Declare Function returnNothing Lib "D:\DEVELOP\ALL16_32\myproj\Debug\myproj.dll" Alias "_returnNothing@4" (ByVal nDays As Integer) As Integer
ps:
As a real problem with Long any suggestions
-
Nov 27th, 2000, 01:17 PM
#8
Monday Morning Lunatic
If you use a .DEF file then you don't actually need the extern "C", since it causes the linker to rename the external references anyway.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 27th, 2000, 06:11 PM
#9
Hyperactive Member
yeah, but its really weird, i've tried it with just __stdcall and a DEF file, and it doesn't work from VB for me. having extern "C" works though.
buzzwords are the language of fools
-
Nov 28th, 2000, 05:01 AM
#10
Hyperactive Member
well, got that working
Yep, got that working extern "C" _cdecl and _dllexport
Another problem arouse with VB, cannot send a LONG to c++ dll and return it .. any thoughts.?
Cheers
-
Nov 28th, 2000, 05:29 PM
#11
Hyperactive Member
do you mean something like:
Declare Sub AddOne Lib "lala.dll" (Num as Long)
the c++ func should be:
extern "C" void __stdcall AddOne(long *num)
{
*num ++;
}
the thing you're probably doing wrong is not declaring the number as a pointer in the C++ function if you simply do
..(long num) then any changes won't affect the original number.
buzzwords are the language of fools
-
Nov 29th, 2000, 05:50 AM
#12
Hyperactive Member
neally
extern "C" long __stdcall AddOne(long *num)
{
return *num;
}
What, does this work, i'll try it in VB.
Cheers
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
|
Click Here to Expand Forum to Full Width
|