|
-
May 4th, 2004, 06:06 AM
#1
Thread Starter
Hyperactive Member
Convert C++ dll function declaration to VB *RESOLVED*
Hi,
I have a C++ dll which has the following function prototype declared in it.
VB Code:
Short Int Send_RS232_Command(unsigned char, unsigned char *const, unsigned char, unsigned char *const, long)
I am trying to use this dll from VB.
Code I have so far is.
VB Code:
Option Explicit
Option Base 0
Private Declare Function Send_RS232_Command Lib "RS232V2.dll" Alias "?Send_RS232_Command@@YAFEQAEE0J@Z" _
(ByVal bBoardAddress As Byte, ByRef bTxDataArray As Byte, _
ByVal bTxDataLength As Byte, ByRef bRxDataArray As Byte, ByVal lRxDataLength As Long) As Integer
Private Sub cmdSend_Click()
Dim iRet As Integer
Dim bBoardAddress As Byte
Dim bTxDataArray(10) As Byte
Dim bTxDataLength As Byte
Dim bRxDataArray(10) As Byte
Dim lRxDataLength As Long
bBoardAddress = 1
bTxDataArray(0) = 0
bTxDataArray(1) = 1
bTxDataArray(2) = 2
bTxDataArray(3) = 3
bTxDataArray(4) = 4
bTxDataLength = 5
iRet = Send_RS232_Command(bBoardAddress, bTxDataArray(0), bTxDataLength, bRxDataArray(0), lRxDataLength)
End Sub
I get the error "Bad DLL Calling Convention".
Is this because I have incorrectly declared the function?
Last edited by Simon Caiger; May 4th, 2004 at 07:59 AM.
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
May 4th, 2004, 07:59 AM
#2
Thread Starter
Hyperactive Member
So I did the usual self doubting, am I going mad bit for a couple of hours and then I discovered that I have been wrestling with another Microsoft bug.
http://support.microsoft.com/default...;en-us;Q153586
You can not call a C function in a dll from the VB IDE if the function uses the _cdecl calling convention.
If you compile and run the VB .exe, it works fine.
Not to good for debugging then
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
May 4th, 2004, 10:53 AM
#3
Fanatic Member
Do you have the DLL source? If so change the calling convention to __stdcall and it will work through the IDE.
-
May 4th, 2004, 10:58 AM
#4
Thread Starter
Hyperactive Member
Thanks for the reply.
Thats what the Knowledge Base article I linked to suggests.
Unfortunately, I do not have the source code
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
May 4th, 2004, 06:15 PM
#5
The picture isn't missing
You can write a dll in c++ that calls your RS232 dll, and have your vb program call your dll. This way, you could make your dll have the stdcall.
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
|