Results 1 to 6 of 6

Thread: Help: "ByRef argument type mismatch"

  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.

  2. #2
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Help: "ByRef argument type mismatch"

    you need to initiate the string with RtlInitString.

    This is an assembler snippet to create a process
    Code:
    ;Initilize and count the string. Store in pEXEansi string structure
    invoke RtlInitString,addr pEXEansi,addr szEXE
    ;Convert the string to a unicode string and count. Store in pEXEuni string structure
    invoke RtlAnsiStringToUnicodeString,addr pEXEuni,addr pEXEansi,TRUE 
    ;Convert full path to a unicode string. Stor in dospath
    invoke RtlDosPathNameToNtPathName_U,pEXEuni.buffer,addr dospath,0,addr ntpath
    invoke RtlCreateProcessParameters,addr ProcPar,addr dospath,0,0,0,0,0,0,0,0
    where szEXE is the ansistring and pEXEansi is the string structure for ansi and pEXEuni for unicode. You better leave VB and goto assembler if you are going to mess with ntdll.dll
    Last edited by minor28; Jun 19th, 2007 at 05:22 PM.

  3. #3

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

    Re: Help: "ByRef argument type mismatch"

    Quote Originally Posted by minor28
    you need to initiate the string with RtlInitString.

    This is an assembler snippet to create a process
    Code:
    ;Initilize and count the string. Store in pEXEansi string structure
    invoke RtlInitString,addr pEXEansi,addr szEXE
    ;Convert the string to a unicode string and count. Store in pEXEuni string structure
    invoke RtlAnsiStringToUnicodeString,addr pEXEuni,addr pEXEansi,TRUE 
    ;Convert full path to a unicode string. Stor in dospath
    invoke RtlDosPathNameToNtPathName_U,pEXEuni.buffer,addr dospath,0,addr ntpath
    invoke RtlCreateProcessParameters,addr ProcPar,addr dospath,0,0,0,0,0,0,0,0
    where szEXE is the ansistring and pEXEansi is the string structure for ansi and pEXEuni for unicode. You better leave VB and goto assembler if you are going to mess with ntdll.dll
    Well ASM is way over my head so I am not touching that until I take some classes in it. My solution would be to use C++ but problem is I do not know C++ and I am highly familiar with VB6

    So are you basically saying that Unicode strings in VB6 are impossible to do?

  4. #4

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

    Re: Help: "ByRef argument type mismatch"

    Nevermind I figured it out.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help: "ByRef argument type mismatch"

    VB6 strings are natively Unicode. There is no need to do this.

    Quote Originally Posted by minor28
    You better leave VB and goto assembler if you are going to mess with ntdll.dll
    I don't see why.

  6. #6
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Help: "ByRef argument type mismatch"

    Unicode and BSTR are not the same. It's not primary the string problem but all underlying code in VB that's hard to control in lower level programming.
    Last edited by minor28; Jun 20th, 2007 at 07:41 AM.

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