Results 1 to 6 of 6

Thread: an API declaration problem

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    an API declaration problem

    Wheven I put this API call as private or public:

    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

    it gives me an error message saying:

    User-Defined type not defined


    What is rong with that and how do I fix that?
    Baaaaaaaaah

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Change this:
    ... lpSecurityAttributes As SECURITY_ATTRIBUTES ...
    To this:
    ... ByVal lpSecurityAttributes As Long ...
    And when calling the function, just pass zero here.

  3. #3
    Lively Member
    Join Date
    Aug 2001
    Location
    Crossroads of America
    Posts
    72

    Smile

    Not to be picky, but lpSecurityAttributes really ought to be:

    ByVal lpSecurityAttributes As Any

    When calling the function, pass Null.

    The cases where it matters whether this is a Long set to zero or an Any set to Null are rare, but I've run into cases where a Long zero won't work (especially in win2k)

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I had trouble with it on Win2K, to get it to work (it was declared as any), I passed "ByVal 0&". (which probably is the same as Null)
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5
    Megatron
    Guest
    I think CLng(0) would also have worked.

  6. #6
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Originally posted by DaveAMS
    Not to be picky, but lpSecurityAttributes really ought to be:

    ByVal lpSecurityAttributes As Any

    When calling the function, pass Null.
    No way.. MSDN says that if you don't want this variable, pass NULL.

    MSDN's NULL is different from VB's Null.
    When you pass NULL in C++, it passes a pointer whose value is equal to zero (a null pointer).
    When you pass Null in VB, it passes a pointer to a valid Variant whose vt member is VT_NULL. Since the API would think that this is actually a SECURITY_ATTRIBUTES pointer, it would fail.

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