Click to See Complete Forum and Search --> : variables parameters and API oh my!
scuzymoto
May 18th, 2000, 02:38 AM
I am attempting to use the cards.dll (as in solitare). I have it working just fine except this one small exception... When I attempt to use the declared API function cdtDraw it will only work if I pass it literal values... For Example
This works great
call cdtDraw(form1.hdc,1,1,1,1,1)
However this next example raises an illegal operation error. It won't even jump to my error handler. Just kills the app and pops the application error window.
dim nVariable As Integer
nVariable = 1
call cdtDraw(form1.hdc,1,1,nVariable,1,1)
Im new to API, is there some kind of notation that I need to pass with the variable to get it not choke? The other wierd thing is that it works fine in debug mode. Its when I run the compiled exe that it wont accept anything but a literal value.
[Edited by scuzymoto on 05-18-2000 at 02:17 PM]
Sam Finch
May 18th, 2000, 04:10 AM
Can I see the Declaration of your function.
scuzymoto
May 18th, 2000, 04:15 AM
Here ya go... Thanks for your help.
Public Declare Function cdtInit Lib "cards.DLL" _
(ByRef nWidth As Integer, ByRef nHeight As Integer) As Integer
Public Declare Function cdtDraw Lib "cards.DLL" _
(ByVal hDC As Long, ByVal xOrg As Integer, _
ByVal yOrg As Integer, ByVal nCard As Byte, _
ByVal nDraw As Byte, ByVal nColor As Integer) As Integer
Public Declare Function cdtTerm Lib "cards.DLL" () As Integer
I also tried it with integers instead of bytes on the cdtDraw Function...
[Edited by scuzymoto on 05-18-2000 at 02:16 PM]
Sam Finch
May 18th, 2000, 06:48 AM
Squeek, I can't see anything wrong trhere, try declaring nVariable as a byte, otherwise I can't think of anything. Where did you find out about using the DLLs?
scuzymoto
May 18th, 2000, 11:03 PM
Unfortunately I tried all kinds of mixtures of data types and it all boils down to the API won't accept anything but a literal (when compiled that is, it works like a dream in debug mode).
However not to be conquered I spent an hour or so making an if elseif statement as long as your arm last night to get around it so that I wouldn't have to use variables. Sloppy programming and all that but it works. 52 lines of if then statments for every card. If ya can't beat 'em join 'em right.
In answer to your other question. I learned about the exportable functions of the cards.dll (has to be the 32 bit version by the way... the one that ships with 95 won't work with VB) on the microsoft website. Ill include the link. It was designed for C++ but I figured it should be able to port over to VB. And it did.... kinda. Anyway thanks for your help.
http://www.microsoft.com/devonly/MAGS/mind/0396/games.htm
Stevie-O
May 19th, 2000, 01:19 AM
Rule #1 for y'all: Win32 API functions all have Long parameters, and return Long values. If anybody here remembers doing API in VB 3.0, they know that the 16-bit SendMessage() function had an Integer value for the wParam parameter (the W is for Word, an unsigned integer). However, the 32-bit SendMessage() function has a Long value for the wParam parameter. This is because 32-bit functions all have 32-bit parameters. You can usually get away with using integers and bytes, because VB will convert for you, but it's not a good idea.
Secondly...are you running NT?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.