Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FileSystemObject in VB returns the wrong value when used from .NET

FileSystemObject in VB returns the wrong value when used from .NET

Scheduled Pinned Locked Moved C#
csharpcomhelpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RickardB
    wrote on last edited by
    #1

    I have constructed a COM object in VB6 that exposes various methods to handle custom files. This object works very well when I use it from a normal VB6 project, but when I use it through COM Interop in a C# application a strange error appear: Inside one of the functions in the COM dll I use the FileExists method on a FileSystemObject. When this method is called from the C# code FileExists returns false, even though the file exists. When the same method is called with the same filename as parameter in VB everything works. Anyone who have any idea of what I am doing wrong? Rickard

    H R 2 Replies Last reply
    0
    • R RickardB

      I have constructed a COM object in VB6 that exposes various methods to handle custom files. This object works very well when I use it from a normal VB6 project, but when I use it through COM Interop in a C# application a strange error appear: Inside one of the functions in the COM dll I use the FileExists method on a FileSystemObject. When this method is called from the C# code FileExists returns false, even though the file exists. When the same method is called with the same filename as parameter in VB everything works. Anyone who have any idea of what I am doing wrong? Rickard

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You should debug both projects (start debugging the C#/.NET client in VS.NET and then start your VS6 and attach to the process) and see what string is getting passed to the COM object. The behavior shouldn't really change from caller to caller except when parameters differ. A different value might be getting marshaled to your COM object than what you're passing from your C# code. My initial thought is that there is a Unicode vs. ASCII problem with string encodings. .NET stores Unicode strings internally and your VB6 control might not be expecting that. See the VB6 StrConv function for information pertaining to converting from/to Unicode strings.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      R 3 Replies Last reply
      0
      • R RickardB

        I have constructed a COM object in VB6 that exposes various methods to handle custom files. This object works very well when I use it from a normal VB6 project, but when I use it through COM Interop in a C# application a strange error appear: Inside one of the functions in the COM dll I use the FileExists method on a FileSystemObject. When this method is called from the C# code FileExists returns false, even though the file exists. When the same method is called with the same filename as parameter in VB everything works. Anyone who have any idea of what I am doing wrong? Rickard

        R Offline
        R Offline
        Rocky Moore
        wrote on last edited by
        #3

        One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com

        R 2 Replies Last reply
        0
        • R Rocky Moore

          One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com

          R Offline
          R Offline
          RickardB
          wrote on last edited by
          #4

          Thanks, will keep this in mind. Rickard

          1 Reply Last reply
          0
          • H Heath Stewart

            You should debug both projects (start debugging the C#/.NET client in VS.NET and then start your VS6 and attach to the process) and see what string is getting passed to the COM object. The behavior shouldn't really change from caller to caller except when parameters differ. A different value might be getting marshaled to your COM object than what you're passing from your C# code. My initial thought is that there is a Unicode vs. ASCII problem with string encodings. .NET stores Unicode strings internally and your VB6 control might not be expecting that. See the VB6 StrConv function for information pertaining to converting from/to Unicode strings.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            R Offline
            R Offline
            RickardB
            wrote on last edited by
            #5

            Good tip! I had actually start to think in those lines! Thanks! Rickard

            1 Reply Last reply
            0
            • H Heath Stewart

              You should debug both projects (start debugging the C#/.NET client in VS.NET and then start your VS6 and attach to the process) and see what string is getting passed to the COM object. The behavior shouldn't really change from caller to caller except when parameters differ. A different value might be getting marshaled to your COM object than what you're passing from your C# code. My initial thought is that there is a Unicode vs. ASCII problem with string encodings. .NET stores Unicode strings internally and your VB6 control might not be expecting that. See the VB6 StrConv function for information pertaining to converting from/to Unicode strings.

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              R Offline
              R Offline
              RickardB
              wrote on last edited by
              #6

              The COM dll is written in Visual Basic. Could you describe to me how I can attach to this process and debug it using VB6? I can't find any attach to process in my VB6.. Rickard

              R 1 Reply Last reply
              0
              • R RickardB

                The COM dll is written in Visual Basic. Could you describe to me how I can attach to this process and debug it using VB6? I can't find any attach to process in my VB6.. Rickard

                R Offline
                R Offline
                RickardB
                wrote on last edited by
                #7

                I solved it! Found a good article on this URL http://support.microsoft.com/?kbid=811658 Rickard

                1 Reply Last reply
                0
                • H Heath Stewart

                  You should debug both projects (start debugging the C#/.NET client in VS.NET and then start your VS6 and attach to the process) and see what string is getting passed to the COM object. The behavior shouldn't really change from caller to caller except when parameters differ. A different value might be getting marshaled to your COM object than what you're passing from your C# code. My initial thought is that there is a Unicode vs. ASCII problem with string encodings. .NET stores Unicode strings internally and your VB6 control might not be expecting that. See the VB6 StrConv function for information pertaining to converting from/to Unicode strings.

                  -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                  R Offline
                  R Offline
                  RickardB
                  wrote on last edited by
                  #8

                  Hi, I have now debugged my application and the string seems to be alright, but it still doesn´t work, or actually it worked for a while, but suddenly the same error occured again. Could this be some kind of access problem? Could it make a difference in I run the com in process or out of process? Rickard

                  H 1 Reply Last reply
                  0
                  • R Rocky Moore

                    One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com

                    R Offline
                    R Offline
                    RickardB
                    wrote on last edited by
                    #9

                    Hi, I have now debugged my application and the string seems to be alright, but it still doesn´t work, or actually it worked for a while, but suddenly the same error occured again. Could this be some kind of access problem? Could it make a difference in I run the com in process or out of process? Rickard

                    1 Reply Last reply
                    0
                    • R RickardB

                      Hi, I have now debugged my application and the string seems to be alright, but it still doesn´t work, or actually it worked for a while, but suddenly the same error occured again. Could this be some kind of access problem? Could it make a difference in I run the com in process or out of process? Rickard

                      H Offline
                      H Offline
                      Heath Stewart
                      wrote on last edited by
                      #10

                      No, it would be an access problem if one client could access it via your COM component but another client couldn't, unless they were running with different credentials (something you have to manually do through several steps). This sounds more like a marshaling problem as I mentioned before. Your COM component can only run as an out-of-process server if it is a stand-alone executable (.exe), so that's not even a valid case. Since it worked before, you're obviously doing something right. Since it changed, you should figure out what changed. Two compiled applications don't magically change. If this is a marshaling problem, make sure you understand that Windows 9X/ME (Windows) use ASCII while Windows NT/2000/XP(/future versions of Windows) (Windows NT) use Unicode. I can't remember exactly how VB handles strings, but you can code your .NET applications to P/Invoke methods using either ASCII or Unicode depending on the OS type, which it will automatically do for you (see CharSet.Auto). I don't remember exactly how VB deals with the different OSes. Find out how that works and make sure your .NET application marshals the string accordingly appropriately on either of the Windows OS system type.

                      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups