Click to See Complete Forum and Search --> : C - VB type conversion problem?


Markmcdade
January 1st, 2000, 07:57 PM
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.

Crazy D
January 2nd, 2000, 05:42 AM
Have you checked what the return value is?
Debug.Print OpenDB("theDB")

Crazy D :-)
"One ring rules them all"

Lothar Haensler
January 3rd, 2000, 04:23 AM
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.

Markmcdade
January 3rd, 2000, 06:35 PM
it's always = 0

Crazy D @ Work
January 4th, 2000, 02:21 AM
Can you modify the dll to see if the parameters gets there correct?

Crazy D @ Work :-)

Markmcdade
January 6th, 2000, 08:00 AM
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.

January 6th, 2000, 12:11 PM
To pass an empty string try to do with "vbNull". I havent tried this for calls,
but in comparisons it works. Have a try !

;-)