Results 1 to 6 of 6

Thread: Help: "ByRef argument type mismatch"

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    Help: "ByRef argument type mismatch"

    Ok When I try to test my code here I get a

    Compile error:
    ByRef argument type mismatch


    Here is the code:
    Code:
    Private Type ANSI_STRING
           Length           As Long
           MaximumLength    As Long
           Buffer           As Long
    End Type
    
    Private Type UNICODE_STRING
           Length           As Long
           MaximumLength    As Long
           Buffer           As Long
    End Type
    
    Private Declare Function RtlAnsiStringToUnicodeString Lib "ntdll.dll" (DestinationString As UNICODE_STRING, SourceString As ANSI_STRING, ByVal AllocateDestinationString As Boolean) As Long
    
    '_____________________________________________________________
    
    Private Sub Command1_Click()
    
        Dim UString     As UNICODE_STRING
        Dim AString     As ANSI_STRING
        Dim sKeyPath    As String
       
        sKeyPath = "\Registry\Machine\SOFTWARE"
    
        'Initialize ANSI_STRING:
        AString.Buffer = StrPtr(sKeyPath)
        AString.Length = LenB(sKeyPath)
        AString.MaximumLength = LenB(AString.Buffer)
        
        Dim pMem As Long: pMem = VarPtr(AString)    'get pointer of ANSI_STRING
        
        'Convert ANSI_STRING to UNICODE_STRING:
        'lStatus = RtlAnsiStringToUnicodeString(UString, ByVal VarPtr(AString), False)      'not work (ByRef Mismatch)
        lStatus = RtlAnsiStringToUnicodeString(UString, pMem, False)                        'not work (ByRef Mismatch)
        
        'Return Status:
            MsgBox GetSysMsg(lStatus)
    
    End Sub

    Note: GetSysMsg is a custom function in a module to return an status string based on any API's Return Value (Works for both STATUS and NTSTATUS)


    Ok so here is the problem:
    When ever I try to perform this, I get an error saying:

    Compile error:
    ByRef argument type mismatch

    and it highlights pMem. Well I am a bit confused here to why it is saying this. So I attempted to pass it ByVal and it then says:

    Compile error:
    User-defined type may not be passed ByVal

    so how am I supposed to pass this pointer to the API ??? I mean you would just think "Oh.. pass the structure not the pointer" in which it will execute then, but when it does, it will give a return status of "Invalid Pointer".

    The API wants the pointer, I just need to know how to give it to it without VB giving an error.

    Thanks for your help.



    Here are the links to MSDN for the API and Structures:

    RtlAnsiStringToUnicodeString Function:
    http://msdn2.microsoft.com/en-us/library/ms648413.aspx

    UNICODE_STRING:
    http://msdn2.microsoft.com/en-us/library/aa491546.aspx

    ANSI_STRING:
    http://msdn2.microsoft.com/en-us/library/aa492030.aspx
    Last edited by altf4; Jun 19th, 2007 at 05:06 PM.

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