Current directory for an ActiveX EXE object is set to the location of the system directory and not to the location of the invoking client in Visual Basic .NET or Visual Basic 2005 (834060)
The information in this article applies to:
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic 2005
SYMPTOMSWhen the ActiveX EXE object is instantiated by a Microsoft
Visual Basic .NET or Visual Basic 2005 client, the default directory that files are read from and
that files are written to must be set to the location of the invoking client.
Instead, the ActiveX EXE object uses the %windir%\System32 directory as the
directory that files are read from and that files are written to.WORKAROUNDTo work around this problem, explicitly set the current
working directory of the Visual Basic .NET or Visual Basic 2005 client at run time. To
do this in the code of your ActiveX EXE project, use a public property to store the
value of the current working directory. You
can set this property in the Visual Basic .NET or Visual Basic 2005 client. For example, in Microsoft Visual Basic 6.0, you
can use the following code in your ActiveX EXE project: ' Declare a private variable to store the value of the current working directory.
Private sMyFilePath As String
Public Sub testMethod()
' Concatenate the name of your file with the value of the MyFilePath property
' before opening your file.
Open MyFilePath & "\output0.dat" For Output As #5
Write #5, "writing"
Close #5
End Sub
Private Sub Class_Terminate()
' Concatenate the name of your file with the value of the MyFilePath property
' before opening your file.
Open MyFilePath & "\output1.dat" For Output As #5
Write #5, "terminated"
Close #5
End Sub
' Declare a property get the accessor for the sMyFilePath private variable.
Public Property Get MyFilePath() As String
MyFilePath = sMyFilePath
End Property
' Declare a property let accessor for the sMyFilePath private variable.
Public Property Let MyFilePath(ByVal vNewValue As String)
sMyFilePath = vNewValue
End Property In the Visual Basic .NET or Visual Basic 2005 client, add a reference to the ActiveX EXE object, add a reference to the System.Windows.Forms.dll assembly, and then use the
following code to call the testMethod method of the ActiveX EXE object: ' Create an instance of the ActiveX EXE object.
Dim o As New Project1.Class1()
' Set the MyFilePath property of the ActiveX EXE object to the current working directory.
o.MyFilePath = System.Windows.Forms.Application.StartupPath
' Call the testMethod method of the Active EXE object.
o.testMethod()
' Release the Active EXE object.
o = Nothing REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
315847
How to use ActiveX components in Visual Studio .NET with Visual Basic .NET
For additional information about using ActiveX
Controls with Windows forms in Visual Studio .NET, visit the following
Microsoft Developer Network (MSDN) Web site:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbCOMInterop kbprb KB834060 kbAudDeveloper |
---|
|