FileSystemObject in VB returns the wrong value when used from .NET
-
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
-
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
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-----
-
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
One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com
-
One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com
-
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-----
-
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-----
-
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
I solved it! Found a good article on this URL http://support.microsoft.com/?kbid=811658 Rickard
-
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-----
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
-
One other quick thought, not likely but you might check permissions and the creditials being used. Rocky <>< www.HintsAndTips.com
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
-
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
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-----