CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 1999
    Posts
    10

    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.


  2. #2
    Join Date
    Apr 1999
    Location
    Rotterdam, Netherlands
    Posts
    278

    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"

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    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.


  4. #4
    Join Date
    Nov 1999
    Posts
    10

    Re: C - VB type conversion problem?

    it's always = 0


  5. #5
    Join Date
    Apr 1999
    Location
    Netherlands
    Posts
    181

    Re: C - VB type conversion problem?

    Can you modify the dll to see if the parameters gets there correct?

    Crazy D @ Work :-)

  6. #6
    Join Date
    Nov 1999
    Posts
    10

    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.


  7. #7
    Guest

    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 !

    ;-)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured