Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘component object model’

BUG: You receive a “Class not registered” error message in Visual Basic 6.0 project after you remove Visual Studio .NET or Visual Studio 2005

Symptoms
You have Visual Studio .NET or Visual Studio 2005 installed on your computer. You create a Visual Basic 6.0 project that has a control that is bound to a data source. When you remove Visual Studio .NET or Visual Studio 2005 and then run you Visual Basic 6.0 project, you receive the following error message:

Run-time error ‘713′:
Class not registered.
Looking for object with
CLSID:{59245250-7A2F-11D0-9842-00A0C91110ED}
Resolution
This problem occurs because the Component Object Model (COM) based MSBind.dll is unregistered when you remove Visual Studio .NET or Visual Studio 2005. Visual Basic 6.0 uses MSBind.dll to bind the control to the data source. Therefore, when you run a Visual Basic 6.0 project that has a data-bound control, you receive the run-time error message.

PRB: DCOMCNFG Displays One Class Name For Each ActiveX Server

Symptoms
When using the Distributed Component Object Model (DCOM) ConfigurationUtility (Dcomcnfg.exe), only one class for each ActiveX server appears inthe list of applications. This occurs even though an ActiveX server maycontain several classes, each of which is functioning correctly.
Resolution
DCOM provides server level security. All objects within a server share thesame security settings. Therefore, Dcomcnfg.exe only lists the first object(class) for each ActiveX server registered.

How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0

Symptoms
This article describes how use Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 to build a managed assembly that can be called from Microsoft Visual Basic 6.0.
Resolution
Guidelines for exposing .NET types to COMWhen you want to expose types in a Microsoft .NET assembly to Component Object Model (COM) applications, consider the following COM interop requirements at design time. Managed types (class, interface, struct, enum, and others) interact well with COM client applications when you follow these guidelines: Define interfaces and explicitly implement them in classes. COM interop provides a mechanism to automatically generate an interface that contains all members of the class and the members of its base class. However, it is best to provide explicit interfaces and implement them explicitly.Declare all managed types that you want to expose to COM as public. Only public types in an assembly are registered and exported to the type library. Therefore, only public types are visible to COM. Declare all type members (methods, properties, fields, and events) that you want to expose to COM as public. Members of public types must also be public to be visible to COM. By default, all public types and members are visible. Use the ComVisibleAttribute attribute if you have to hide a type or a member from control type or member visibility to COM client applications.Types must have a public default constructor to be instantiated through COM. Managed, public types are visible to COM. However, without a public default constructor (a constructor without arguments), COM clients cannot create an instance of the type. COM clients can still use the type if the type is instantiated in another way and the instance is returned to the COM client. You may include overloaded constructors that accept varying arguments for these types. However, constructors that accept arguments may only be called from managed (.NET) code.Types cannot be abstract. Neither COM clients nor .NET clients can create instances of abstract types.Use the COMClass template in Visual Basic .NET or in Visual Basic 2005. When you add a new class that you intend to expose to COM applications, consider using the COMClass template that is provided by Visual Basic .NET or by Visual Basic 2005. The COMClass template creates a class that includes the COMClassAttribute attribute and generates GUIDs for the CLSID, the Interface ID, and the Event ID that are exposed by your type. Additionally, the COMClass template creates a public constructor without parameters. This is the easiest way to create a new class that follows the guidelines for creating COM callable types.
Registering the .NET assembly for COM interop and creating a type library For Visual Basic 6.0 to successfully interact with a managed component, you must register the assembly for COM interop and generate a type library. This registration must be performed on each computer where a COM client application interacts with the assembly. The type library provides type information about the exposed types in the assembly to COM client applications. The process for doing this depends on if you are working on the development computer or on the destination computer.
On the development computer, Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 automatically creates a type library and registers it during the build process if the Register for COM Interop check box is selected under the project’s Configuration properties. If you used the COMClass template when you created the class, Visual Studio .NET or Visual Studio 2005 automatically selects the Register for COM Interop check box. To verify that the Register for COM Interop check box is selected in Visual Studio .NET or in Visual Studio 2005, follow these steps: Start Visual Studio .NET or Visual Studio 2005.Open the solution that contains the project that you want to build for COM interop.On the View menu, click Solution Explorer.In Solution Explorer, right-click the project that you want to build for COM interop, and then click Properties.Click Configuration Properties, and then click the Build node.
Note In Visual Studio 2005, click Compile in the left pane.Click to select the Register for COM Interop check box. This option is only enabled in class library projects.Click OK to close the Property Pages dialog box.If Visual Studio .NET or Visual Studio 2005 is not installed or if you have to manually generate and register a type library (.tlb) file for the managed assembly, use the Assembly Registration tool (RegAsm.exe) with the /TLB switch. You should also use the /Codebase switch if the managed assembly is a private assembly and you intend to put the managed assembly in a different folder from the host process (EXE).
A private assembly is deployed with an application and is available for the exclusive use of that application. Other applications do not share the private assembly. Private assemblies are designed to be installed into the same folder as the host process (EXE). With a COM client application, this means that the assembly is located in the same folder as that application. A shared assembly is available for use by multiple applications on the computer. To create a shared assembly, you must sign the assembly with a strong name and install the assembly into the Global Assembly Cache (GAC) on the destination computer.
For more information about how to sign the assembly with a strong name and install the assembly into the Global Assembly Cache (GAC), visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/xc31ft41(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/xc31ft41(vs.71).aspx)You should use both the /tlb: switch and the /Codebase switch when you register the assembly. The /tlb: switch generates and registers a type library, and the /Codebase switch registers the location of the managed assembly in the Windows registry. If you do not use the /Codebase switch and the assembly has not been installed into the Global Assembly Cache (GAC), you must put a copy of the assembly into the folder of each COM client application (EXE) so that the assembly can be located by the common language runtime (CLR).
To generate and register a type library and register the location of the managed assembly, type the following command at the command prompt:
Regasm AssemblyName.dll /tlb: FileName.tlb /codebaseCreate a COM callable assembly inVisual Basic .NETStart Visual Studio .NET or Visual Studio 2005. On the File menu, point to New, and then click Project.Under Project Types, click Visual Basic Projects.
Note In Visual Studio2005 click Visual Basic under Project Types.Under Templates, click Class Library.Name the project TestProj, and then click OK.
By default, Class1 is created.On the View menu, click Solution Explorer.Right-click Class1.vb, and then click Delete. Click OK to confirm the deletion of the Class1.vb source file.On the Project menu, click Add Class.Under Templates, click COM Class.Name the class COMClass1.vb, and then click Open
COMClass1 is created with the following code.

<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _Public Class ComClass1#Region “COM GUIDs”‘ TheseGUIDs provide the COM identity for this class’ and its COM interfaces. If you change them, existing’ clients will no longer be able to access the class.Public Const ClassId As String = “6DB79AF2-F661-44AC-8458-62B06BFDD9E4″Public Const InterfaceId As String = “EDED909C-9271-4670-BA32-109AE917B1D7″Public Const EventsId As String = “17C731B8-CE61-4B5F-B114-10F3E46153AC”#End Region’ A creatable COM class must have a Public Sub New()’ without parameters. Otherwise, the class will not be’ registered in the COM registry and cannot be created’ through CreateObject.Public Sub New()MyBase.New()End SubEnd ClassAdd the following function to COMClass1.

Public Function myFunction() As IntegerReturn 100End FunctionIn Solution Explorer, right-click Project Name, and then click Properties.Under Configuration Properties, click Build.Verify that the Register for COM Interop check box is selected, and then click OK. On the Build menu, click Build Solution to build the project.Start Visual Basic 6.0.On the File menu, click New Project, and then click to select Standard EXE in the New Project dialog box.
By default, a form that is named Form1 is created.On the Project menu, click References. In the Available References list, double-click to select TestProj, and then click OK.Add a command button to the form.Double-click Command1 to open the Code window. Add the following code to the Command1_Click event.

Dim myObject As TestProj.COMClass1Set myObject = New TestProj.COMClass1MsgBox myObject.myFunctionOn the Run menu, click Start.Click the command button.
You should receive a message that displays 100.

How To Implement Visual Basic COM Objects Returning Recordsets

Symptoms
This article describes, by example, how to implement a Visual Basic Component Object Model (COM) Object that returns a recordset to Active Server Pages (ASP).
Implementing this incorrectly can result in memory leaks or one of the following errors:

The operation requested by the application is not allowed if the object is closed. -or-

Type Mismatch -or-

error ‘ASP 0115′ – A trappable error occured in an external object
Resolution
Use the following steps to implement a method that returns a recordset from a Visual Basic COM Object to Active Server Pages: Create a Visual Basic ActiveX DLL project called PassRsPrj.Add a class module and change its name to PassRsObj.Implement the following method:
Note You must change the UID and the PWD values to the ones that are used on your system.

Public Function TestRs() as ADODB.RecordsetDim rsObj As ADODB.RecordsetDim cnObj As ADODB.Connectionset rsObj = New ADODB.Recordsetset cnObj = New ADODB.Connection’Open connection to databasecnObj.Open(“DSN=pubs;uid=<username>;pwd=<strong password>”)’To use disconnected Recordset you must use client side cursorsrsObj.CursorLocation = adUseClientrsObj.Open “select * from authors”, cnObj, adOpenKeyset, _adLockOptimistic, adCmdText’Disconnected recordsetSet rsObj.ActiveConnection = Nothing’Set return valueSet Testrs = rsObj’Clean up resourcescnObj.CloseSet cnObj = NothingEnd Function Create an ASP page with the following code:

<%Dim rsTest, oTestPassRsSet oTestPassRs = Server.CreateObject(“PassRsPrj.PassRsObj”)Set rsTest = oTestPassRs.TestRs()DoResponse.Write ( “Value in Record = ” & rsTest(1) & “<BR>” )rsTest.MoveNextLoop until rsTest.EOFrsTest.CloseSet rsTest = NothingSet oTestPassRs = Nothing%>

How To Create a DCOM Client/Server with Events by Using Visual Basic

Symptoms
This article shows you how to create, package, and deploy a Distributed Component Object Model (DCOM) client/server application with events by using Visual Basic. To create a DCOM client/server application, you need the Enterprise Edition of Visual Basic. Microsoft assumes that the reader is already familiar with creating client/server applications with events that run on the same computer.
Resolution
You do not need to change your code to enable a client application to instantiate a remote server by using DCOM. The difference is the way in which you package and deploy the client. In addition, there are some security settings you need to make after the client and the server are installed. You can make these settings by using an utility called DCOMCNFG. In particular, when your server raises events, not only are the server settings important, but the client ones are too.
The following steps show you how to distribute and configure a simple client/server application. Call the server DCOMDemoEvents_Svr and the client DCOMDemoEvents_Cli. Create a separate folder for each of them and, for the purpose of this article, name the folders c:\DCOMDemoEvents\Server, and c:\DCOMDemoEvents\Client.
Create the Server Start a new Visual Basic Project. In the New Project dialog box, select ActiveX EXE, and then click Open. Class1 is created by default. Add the following code to the Class1 module:

Option ExplicitPublic Event TimeUpdate(sTime As String)Public Sub CallMeBack()RaiseEvent TimeUpdate(Time())End SubPublic Function ServerTime() As String’ this method was included just in case we need’ to test a method without call back.ServerTime = TimeEnd Function On the Project menu, click the Project Properties option.Select the General tab.In the Project Name field, type DCOMDemoEvents_Svr. In the Project Description field, type DCOMDemoEvents_Svr – Server. Select the Component tab, and then select the Remote Server Files option.
NOTE: Selecting this option makes the Visual Basic compiler generate the VBR and TLB files needed for packaging the client applications that use this server. The files contain registry entries that need to be included on the client computer.Close the Project Properties dialog box. On the File menu, select Save As, and then save this project to the c:\DCOMDemoEvents\Server folder. On the File menu, select Make DCOMDemoEvents_Svr and compile the server. On the Project menu, select the Project Properties option, and then select the Component tab. On the Component tab, select Version Compatibility, select the Binary Compatibility option, and then make the project binary compatible with the server’s executable file you just created (DCOMDemoEvents_Svr.exe). By making this option, you are assuring that all GUIDs are kept the same if you recompile the server.
Create the ClientOn the File menu, select the New Project option, select Standard EXE, and click OK. Form1 is created by default. On the Project menu, click the Project Properties option, and then select the General tab.In the Project Name field, type DCOMDemoEvents_Cli. In the Project Description field, type DCOMDemoEvents_Cli Project - Client, and then click OK to close the Project Properties dialog box.On the Project menu, select References, and add a reference to DCOMDemoEvents_Svr – Server. In the General Declarations section of Form1, include the following line:

Dim WithEvents MyEventObj As DCOMDemoEvents_Svr.Class1 This declares the server object with events. After typing in this line, you should see MyEventObj in the list of objects for this form. The list of objects of the form is found in the upper-left-hand combo box in the form’s code module.
From the list of objects of the form, select MyEventObj. The empty Sub MyEventObj_TimeUpdate is created. Type in the following line of code:

MsgBox “Event from Server received. Time=” & sTime Place a command button on Form1, and change the button’s caption to Run with Events.Place the following code in the button’s click event:

On Error GoTo err1Set MyEventObj = CreateObject(“DCOMDemoEvents_Svr.Class1″)MyEventObj.CallMeBackExit Suberr1:MsgBox “Error: ” & Err.Number & ” – ” & Err.Description Place a second command button on Form1, and change the button’s caption to Run without Events. Place the following code in the button’s click event:

Dim MyObj As DCOMDemoEvents_Svr.Class1On Error GoTo err1Set MyObj = CreateObject(“DCOMDemoEvents_Svr.Class1″)MsgBox “Server time without events: ” & MyObj.ServerTimeExit Suberr1:MsgBox “Error: ” & Err.Number & ” – ” & Err.Description Once you have done this, the form’s code should look like the following:

Option ExplicitDim WithEvents MyEventObj As DCOMDemoEvents_Svr.Class1Private Sub Command1_Click()On Error GoTo err1Set MyEventObj = CreateObject(“DCOMDemoEvents_Svr.Class1″)MyEventObj.CallMeBackExit Suberr1:MsgBox “Error: ” & Err.Number & ” – ” & Err.DescriptionEnd SubPrivate Sub Command2_Click()Dim MyObj As DCOMDemoEvents_Svr.Class1On Error GoTo err1Set MyObj = CreateObject(“DCOMDemoEvents_Svr.Class1″)MsgBox “Server time without events: ” & MyObj.ServerTimeExit Suberr1:MsgBox “Error: ” & Err.Number & ” – ” & Err.DescriptionEnd SubPrivate Sub MyEventObj_TimeUpdate(sTime As String)MsgBox “Event from Server received. Time=” & sTimeEnd Sub On the File menu, select Save As, and then save the project to the client’s folder, c:\DCOMDemoEvents\Client. Press the F5 button to run the client in the IDE and test it out. Be aware that this test is local to the development computer at this point. It is running the local ActiveX EXE Server. On the File menu, select Make DCOMDemoEvents_Cli to compile the client, and then close Visual Basic.
Package the Server Use the Package and Deployment Wizard to package your server for distribution as usual. The server is instantiated by a remote client using DCOM. While creating the package for your server, you get a dialog box asking you if this server will be used as a Remote Automation server and if you want to include support files for this purpose. Just click NO because DCOM is not Remote Automation. Remote Automation is an older technology which was replaced by DCOM.
Package the Client When you package the client, there are some specific steps that need to be taken, considering that the server does not run on the same computer as the client. The changes made to the client’s package assure that only the type library (.tlb file) is installed and some additional registry entries are included instead of the server’s executable on the client’s computer. You do not need the server’s executable installed in the client’s computer because it is not going to run there.
Package the client following these steps: Start the Package and Deployment Wizard, and then select the Client’s project. Click the Package button. In the Package Type dialog box, select Standard Setup Package, and then click Next. In the Package Folder dialog box, select the folder where the package is stored, and then click Next. In this case, it is c:\DCOMDemoEvents\Client\Package.
NOTE: You may get a dialog box saying that there is no dependency information for your server. Click OK because your server doesn’t have any dependencies.
You should now be in the Included Files dialog box.
Deselect the server’s executable file, DCOMDemoEvents_Svr.exe. You do not want to distribute the server’s executable.Click the Add button, and change the Files of Type combo box to Remote Server Files (*.vbr). Point to the folder where you have your Server’s project, in this case, c:\DCOMDemoEvents\Server, and then select the related VBR file DCOMDemoEvents_Svr.VBR. Click Open and the Add File dialog box closes. Note that two files are included, DCOMDemoEvents_Svr.VBR and DCOMDemoEvents_Svr.TLB. Click Next. In the Remote Servers dialog box, define the name of the computer (Net Address) where the server will be running.
Usually you keep this field blank because you may not know in advance where the server is installed. If you keep it blank, you are prompted for it when you install the client. For this example, keep it blank.
Click Next to proceed. You can now proceed with the standard procedures for Package and Deployment Wizard. In our example, click Next to all remaining dialog boxes.
Install the Server Install the server on the computer on which you would like to run it, using the distribution package you created earlier. If you want to use your development computer to run the server, you don’t need to install it because Visual Basic makes the registration for you when it compiles the server.
Install the Client Install the Client on the computer on which you would like to run it, using the distribution package you created earlier. Because this client uses a DCOM server and you left the actual location of the server blank when you created the distribution package, you now need to provide this location. When Setup prompts you for this location, provide the name of the computer where you installed the server.
Set the Server’s Security If you installed the server on a Microsoft Windows NT or Microsoft Windows 2000 computer, you need to configure security for it. Do this by using DCOMCNFG, as shown in the following steps, which assume that both client and server computers are part of a domain, and the user logged on to the client computer is logged on as a domain user. The suggested settings are just one possible configuration. They are very generic and give wide access to the server. Remember that this is just an example. When you deploy your real applications, and security is a concern for your environment, you should select more restrictive options. Also, if the computer you are using to test this example server is used to run other servers, make a note of the current settings before you make the following changes, and return to the original settings as soon as you are done with your tests. On the server computer, click the Start button, and then select Run. In the Run dialog box, type DCOMCNFG, and then click OK. You need to have Administrator rights to be able to run DCOMCNFG.Select the Default Properties tab, and verify that Enable Distributed COM on this computer is checked.Set the Default Authentication Level to Connect, and set the Default Impersonation Level to Identify.Select the Default Security tab.Click the Edit Default button in the Default Access Permissions panel.Verify that Everyone and System are included in the list with Allow Access rights. If they are not, you can use the Add button to add them to the list. Click OK when the list is complete.Click the Edit Default button in the Default Launch Permissions panel.Verify that Everyone and System are included in the list with Allow Launch permissions. If they are not, use the Add button to add them to the list. Click OK when the list is complete.Select the Applications tab, highlight your server, DCOMDemo_Svr.Class1, and then click the Properties button. Select the General tab, set the Authentication Level to Default, and then select the Location tab. The only option checked should be Run application on this computer.Select the Security tab and verify that the Use default access permissions and the Use default launch permissions options are checked.Select the Identity tab, check The launching user option, click OK to close the Server’s Properties dialog box, and then click OK again to close DCOMCNFG. As you can see, the test server uses all of the default settings. When deploying your own servers, you should define settings specific to your application. All custom settings take precedence over the default ones.
You are now ready to test your server. On the client computer, launch the client, and then click the Run button. You should see a message box indicating the server’s time. If you are unable to test this sample successfully, please see the troubleshooting article, Q269330, listed in the “References” section.
Set the Client Security Because the DCOM server exposes events that the client application consumes, you must also set DCOM permissions on the client computer to allow the server to make callbacks to the client. If your DCOM server does not expose events, or if your client application does not consume me events, you do not have to perform this step. On the client computer, click Start, and then click to select Run. In the Run dialog box, type DCOMCNFG, and then click OK.
You must have administrator rights to run DCOMCNFG.Click the Default Properties tab, and then verify that Enable Distributed COM on this computer is checked.Set the Default Authentication Level to Connect, and then set the Default Impersonation Level to Identify. Click the Default Security tab. Click the Edit Default button in the Default Access Permissions panel.Verify that Everyone and System are included in the list with Allow Access Rights. If they are not included in the list, use the Add button to add them to the list. Click OK when the list is complete.

How To Create a DCOM Client/Server Application by Using Visual Basic

Symptoms
This article shows you how to create, package, and deploy a Distributed Component Object Model (DCOM) client/server application by using Visual Basic. To create a DCOM client/server application, you need the Enterprise Edition of Visual Basic. Microsoft assumes that the reader is already familiar with creating client/server applications that run on the same computer.
Resolution
You do not need to change your code to enable a client application to instantiate a remote server by using DCOM. The difference is the way in which you package and deploy the client. In addition, there are some security settings you need to make after the client and the server are installed. You can make these settings by using an utility called Dcomcnfg.
The following steps show you how to distribute and configure a simple client/server application. Name the server DCOMDemo_Svr, and name the client DCOMDemo_Cli. Create a separate folder for each of them. For the purpose of this article, call these folders c:\DCOMDemo\Server and c:\DCOMDemo\Client.
Create the ServerStart a new Visual Basic Project. On the New Project dialog box, select ActiveX EXE, and then click Open. Class1 is created by default. Add the following code to the Class1 module:

Public Function ServerTime() As StringServerTime = TimeEnd Function On the Project menu, click the Project Properties option, and then select the General tab.In the Project Name field, type in DCOMDemo_Svr.On the Project Description field, type in DCOMDemo_Svr – Server. Check the Unattended Execution option.
NOTE: This option should always be checked in servers that don’t have any UI to assure that no dialog boxes of any type are displayed while the server is running. If you have any type of user interaction while your server is running under an identity that is not the Interactive User, your server may appear to hang.Select the Component tab, and check the Remote Server Files option.
NOTE: Checking this option makes the Visual Basic compiler generate the VBR and TLB files needed for packaging the client applications that use this server. These files contain registry entries that need to be included on the client computer.Close the Project Properties dialog box.On the File menu, select Save As, and then save this project to the c:\DCOMDemo\Server folder.On the File menu, select Make DCOMDemo_Svr and compile the server.On the Project menu, select the Project Properties option, and then select the Component tab.On the Component tab, select Version Compatibility, select the Binary Compatibility option, and then make the project binary compatible with the server’s executable file you just created (DCOMDemo_Svr.exe). By selecting this option you are assuring that all GUIDs are kept the same if you recompile the server.
Create the ClientOn the File menu, select the New Project option, select Standard EXE, and then click OK. Form1 is created by default.On the Project menu, click the Project Properties option, and then select the General tab.In the Project Name field, type in DCOMDemo_Cli. In the Project Description field, type in DCOMDemo_Cli Project – Client.On the Project menu, select References. From the list of available references, select DCOMDemo_Svr – Server. Place a command button on Form1, and change the button’s caption to Run.Place the following code in the button’s click event:

Dim MyObj As DCOMDemo_Svr.Class1On Error GoTo err1Set MyObj = CreateObject(“DCOMDemo_Svr.Class1″)MsgBox “Server Time=” & MyObj.ServerTime & “Client Time=” & TimeExit Suberr1:MsgBox “Connection failed: Error ” & Err.Number & ” – ” & Err.Description On the File menu, select Save As, and then save the project to the client’s folder c:\DCOMDemo\Client. Press the F5 key to run the client in the IDE and test it out.On the File menu, select Make DCOMDemo_Cli to compile the client, and then close Visual Basic.
Package the ServerUse the Package and Deployment Wizard to package your server for distribution as usual. The server is instantiated by a remote client using DCOM. While creating the package for your server, you get a dialog box asking you if this server will be used as a Remote Automation server and if you want to include support files for this purpose. Just click the No button, because DCOM is not Remote Automation. Remote Automation is an older technology that was replaced by DCOM.
Package the ClientWhen packaging the client there are some specific steps that need to be taken, considering that the server does not run on the same computer as the client. The changes made to the client’s package assure that just the type library (.tlb file) is installed and some additional registry entries are included instead of the server’s executable, which is not necessary on the client’s computer because it’s not going to run there.
Package the client by using the following steps:Start Package and Deployment Wizard, and then select the Client’s project.Click the Package button. In the Package Type dialog box, select Standard Setup Package, and then click Next.In the Package Folder dialog box, select the folder to store the package, and then click Next. In this case, it is c:\DCOMDemo\Client\Package.
NOTE: You may get a dialog box saying that there is no dependency information for the server. Click OK because this server doesn’t have any dependencies.
You should now be in the Included Files dialog box. Deselect the server’s executable file, DCOMDemo_Svr.exe, because you do note want to distribute the server’s executable, and then click the Add button. Change the Files of Type combo box to Remote Server Files (*.vbr).Point to the folder where you have your Server’s project (in this case c:\DCOMDemo\Server), and select the related VBR file, DCOMDemo_Svr.VBR. Click Open, and the Add File dialog box closes. Notice that two files are included, DCOMDemo_Svr.VBR and DCOMDemo_Svr.TLB. Click the Next button.
NOTE: In the Remote Servers dialog box you can define the name of the computer (Net Address) where the server is running. Usually you keep this field blank because you may not know in advance where the server will be installed. If you keep it blank, you are prompted for it when you install the client. For this sample, keep it blank.Click Next to proceed. You can now proceed with the standard procedures for Package and Deployment Wizard. In this case, just click Next to all remaining dialog boxes
Install the ServerInstall the server on the computer on which you would like to run it, using the distribution package you created earlier. If you want to use your development computer to run the server, you don’t need to install it because Visual Basic makes the registration for you when it compiles the server.
Install the ClientInstall the Client on the computer on which you would like to run it, using the distribution package you created earlier. Because this client uses a DCOM server and you left the actual location of the server blank when you created the distribution package, you now need to provide this location. When Setup prompts you for this location, provide the name of the computer where you installed the server.
Set the Server’s SecurityIf you installed the server on a Microsoft Windows NT or Microsoft Windows 2000 computer, you need to configure security for it. Do this by using Dcomcnfg, as shown in the following steps, which assume that both client and server computers are part of a domain, and the user logged on to the client computer is logged on as a domain user. The suggested settings are just one possible configuration. They are very generic and give wide access to the server. Remember that this is just an example. When you deploy your real applications, and security is a concern for your environment, you should select more restrictive options. Also, if the computer you are using to test this example server is used to run other servers, make a note of the current settings before you make the following changes, and return to the original settings as soon as you are done with your tests.On the server computer, click the Start button, and then select Run. In the Run dialog box, type Dcomcnfg, and then click OK. You need to have Administrator rights to be able to run Dcomcnfg.Select the Default Properties tab, and verify that Enable Distributed COM on this computer is checked.Set the Default Authentication Level to Connect, and set the Default Impersonation Level to Identify.Select the Default Security tab.Click the Edit Default button in the Default Access Permissions panel.Verify that Everyone and System are included in the list with Allow Access rights. If they are not, you can use the Add button to add them to the list. Click OK when the list is complete.Click the Edit Default button in the Default Launch Permissions panel.Verify that Everyone and System are included in the list with Allow Launch permissions. If they are not, use the Add button to add them to the list. Click OK when the list is complete.Select the Applications tab, highlight your server, DCOMDemo_Svr.Class1, and then click the Properties button. Select the General tab, set the Authentication Level to Default, and then select the Location tab.The only option that is checked should be Run application on this computer.Select the Security tab and verify that the Use default access permissions and the Use default launch permissions options are checked.Select the Identity tab, check The launching user option, click OK to close the Server’s Properties dialog box, and then click OK again to close Dcomcnfg.As you can see, the test server uses all of the default settings. When deploying your own servers, you should define settings specific to your application. All custom settings take precedence over the default ones.
You are now ready to test your server. On the client computer, launch the client, and then click the Run button. You should see a message box indicating the server’s time. If you are unable to test this sample successfully, please see the troubleshooting article, Q269330, listed in the “References” section.