C - VB type conversion problem?
Hi, could anyone please shed some light on what I'm doing wrong?
I'm trying to get a true value from a C function, but it always returns false.
In my C DLL, I have the function header as
BOOL Open(PSTR filename)
in my VB project, I first have the declaration as:
private Declare Function OpenDB Lib "DataBase.dll" Alias "Open" (byval txtFile as string) as Long
and then, as a procedure:
private Sub Form_Load()
Dim opened as Long
opened = OpenDB("theDB")
If opened = 1 then
lblRecordCounter = "DATABASE OPENED"
else
lblRecordCounter = "DATABASE CLOSED"
End If
End Sub
I don't get any errors, just a "DATABASE CLOSED" all the time rather than a "DATABASE OPENED".
Can anyone please tell me what I'm doing wrong?
Thanks for any help
Mark.
Re: C - VB type conversion problem?
Have you checked what the return value is?
Debug.Print OpenDB("theDB")
Crazy D :-)
"One ring rules them all"
Re: C - VB type conversion problem?
better change your VB code to
if opened = 0 then
...database closed"
else
... database opened
end if
even better: make your C-DLL an ActiveX dll and raise an error that can be trapped by the VB program. That way, you'd be able to give the VB client some useful error information.
Re: C - VB type conversion problem?
Re: C - VB type conversion problem?
Can you modify the dll to see if the parameters gets there correct?
Crazy D @ Work :-)
Re: C - VB type conversion problem?
I discovered that if a string is passed, the function looks for that name, and opens the file.
To create a new file, a null pointer must be passed. Any ideas how to do this?
I tried
openDB(null)
openDB("")
but none seemed to work.
Re: C - VB type conversion problem?
To pass an empty string try to do with "vbNull". I havent tried this for calls,
but in comparisons it works. Have a try !
;-)