| | |
Trouble calling VB function from C DLL
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I've been able to design a front-end for a C DLL, calling the DLL functions from the VB program but I'm having trouble calling the VB functions from the C DLL. Maybe I should have put this in the C forum, but I don't know.
If I have this in a VB module:
and
Well, the DLL compiles, and the VB program runs, but when I try to call the callback function, it says bad DLL calling convention. I tried taking the address by pointer as well (since I was able to pass values by pointer in the past, I figured it would work this time also) to no avail. And I commented out all the code in the function to see if that was the problem, but it wasn't--it's the VB program calling the callback function, which is using a "bad convention." The only difference I can see between the working code and the broken code, is that I'm using a Long data type, and that I'm not returning a value (which shouldn't matter...right?)
I used DUMPBIN /EXPORTS to check the exports of the DLL and I get:
I checked the data types for VB6 and it says a long is 4 bytes, and if I compile the DLL using int, long, or short the DLL export always asks for 4 bytes in parameters, so I don't know what I'm doing wrong... Any ideas? Maybe I'll link to this in the C forum as well
If I have this in a VB module:
vb Syntax (Toggle Plain Text)
Public Declare Function callback Lib "C:\c\dll\mydll" (ByVal cbAddress As Long) Public Sub cb() MsgBox "Called back." End Sub
callback AddressOf cb is used for the even of a button click or something. In a C DLL I would use this: c Syntax (Toggle Plain Text)
EXPORT void __stdcall callback(long cbAddress){ typedef void (__stdcall *funcp)(); funcp VBCallback; VBCallback = (funcp)cbAddress; VBCallback(); }
I used DUMPBIN /EXPORTS to check the exports of the DLL and I get:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
1 0 00001190 callback 2 1 00001190 callback@4
I wake up! And my mind's out, never again will I sell out. Converting vegetarians.
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
fix'd.
Know what the problem was?
The function in the DLL doesn't return a value, so it should have been
you would think VB could have just told me that since I didn't add "As ___" to the end of it, but, oh well.
Know what the problem was?
vb Syntax (Toggle Plain Text)
Public Declare Function callback Lib "C:\c\dll\mydll" (ByVal cbAddress As Long)
vb Syntax (Toggle Plain Text)
Public Declare Sub callback Lib "C:\c\dll\mydll" (ByVal cbAddress As Long)
you would think VB could have just told me that since I didn't add "As ___" to the end of it, but, oh well.
I wake up! And my mind's out, never again will I sell out. Converting vegetarians.
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
![]() |
Similar Threads
- calling a function in DLL file ??? (C++)
- Calling a function in html file from c# code (C#)
- calling function name? i need help (PHP)
- @@Creating DLL in @@ (C++)
- Having trouble calling certain functions (C++)
- Calling function in dll (Assembly)
- Helping with calling a function (C)
- Calling C function from MATLAB (C)
- Still need info on calling a function from bool! (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Update Binary Field in sql server 2000
- Next Thread: Convert byte Array to string + VB 6.0
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





