Share via


Step 3: Creating the SimpleSample DLL (C# Tutorial) [Office 2003 SDK Documentation]

Previous   Step 2: Setting Up the C# Project

The smart document dynamic-link library (DLL) contains the actions and logic for the smart document. The following procedure shows you how to create a smart document DLL using C#.

  1. In the clsActions class module, insert the code that specifies that your code uses the ISmartDocument interface.

    Important   If you copied all the code from the SimpleSample smart document code module, you can go to step 7. However, you might want to read through to step 8 to understand what each of the subroutines does.

  2. Insert the code that specifies the base class for Class1.

  3. Insert the code for the smart document constants.

  4. Insert the SmartDocInitialize method. (There is no code to insert into this method.)

  5. Define the number of types (or elements) that will have controls and actions assigned to them. For the SimpleSample smart document, there is one type, cTEXTBOX.

    • Insert the code for the SmartDocXmlTypeCount property to specify the number of elements that will have controls and actions assigned to them.
    • Insert the code for the SmartDocXmlTypeName property to assign names to the element constants that you specified earlier.
    • Insert the code for the SmartDocXmlTypeCaption property to specify the caption that will appear in the Document Actions task pane for the type.
  6. Define the number of controls for each of the types specified earlier. Each type can have one or more controls associated with it, and each of those controls can be any of the controls specified in the C_TYPE constants.

    • Insert the code for the ControlCount property to specify the number of controls that you want to create for each of the types specified earlier.

    • Insert the code for the ControlID property to provide a unique identifier for each of the controls in the smart document.

    • Insert the code for the ControlNameFromID property to specify a friendly name that you can use to access each of your controls from the application's Visual Basic for Applications (VBA) object model.

    • Insert the code for the ControlCaptionFromID property to specify the caption that will appear in the Document Actions task pane for each of the controls.

    • Insert the code for the PopulateTextboxContent method to specify what happens when the control is displayed.

      Note  This subroutine is empty because you are not specifying actions for the text box when it is displayed initially in the Document Actions task pane. However, by using the PopulateTextboxContent method, you could initially populate a text box with data from a database or another source.

    • Insert the code for the OnTextboxContentChange method to specify what happens when the contents of the text box control change.

      Note  You need to add a reference to the "System.Windows.Forms" namespace in order to use the MessageBox object in this code.

  7. This is all the code necessary for the first part of the SimpleSample smart document. However, the ISmartDocument interface requires that all methods and properties be present, regardless of whether they contain code. Therefore, add blank subroutines for the remaining methods and properties.

  8. Modify and run the SetPolicy.bat file.

Note  If Microsoft Office Word 2003 is running when you run the SetPolicy.bat file, you must restart Word before opening the SimpleSample smart document.

Next   Step 4: Compiling the SimpleSample DLL