Results 1 to 9 of 9

Thread: string to ref string error ??[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    string to ref string error ??[Resolved]

    This is weird . Below, the method signature is marked as ByRef . I exported this class to dll file . It works fine in VB. In C# , it gives me two strange errors .They say : Argument '1': cannot convert from 'string' to 'ref string'
    and
    Argument '2': cannot convert from 'string' to 'ref string'

    VB Code:
    1. Public Shared Function FindFile(ByRef RootPath As String, ByRef FileName As String) As String

    I used it like this :

    Code:
    MessageBox.Show(FindFileViaAPI.FileClass.FindFile("c:\\" ,"setup.exe"));
    Anyone knows why ?
    Last edited by Pirate; Aug 11th, 2003 at 10:09 AM.

  2. #2
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    Have you tryed to this?:
    Code:
    MessageBox.Show(FindFileViaAPI.FileClass.FindFile(@"c:\\" ,"setup.exe"));
    Hope thats it,

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    have you tried adding ref, eg:
    VB Code:
    1. MessageBox.Show(FindFileViaAPI.FileClass.FindFile([COLOR=blue]ref[/color] "c:\\" ,[COLOR=blue]ref[/color] "setup.exe"));
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    What dynamic_sysop said. See, in C# you have to use the ref keyword when passing in a value type variable by reference. Its a little different with reference types.

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Sgt-Peppa
    Have you tryed to this?:
    Code:
    MessageBox.Show(FindFileViaAPI.FileClass.FindFile(@"c:\\" ,"setup.exe"));
    Stephan
    The same error arised again .

    and

    When I tried what dynamic_sysop said , it gives this error :
    A ref or out argument must be an lvalue



  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this
    Code:
    string _rootPath = @"C:\";
    string _fileName = "setup.exe";
    
    MessageBox.Show(FindFileViaAPI.FileClass.FindFile(ref _rootPath, ref _fileName));

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanks , this works well . Do you know why ?

  8. #8
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    As to what the error said, you have to use an lvalue.

  9. #9

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Cool .

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