If you distribute your application (EXE) files via one of the major online services such as CompuServe, America Online, or the Internet, you're probably aware that you can't easily restrict how often users will copy your software, or how they might try to redistribute it. If you create an About box that displays copyright information, you've protected yourself somewhat. However, any user who has access to a resource editor such as Resource Workshop (the editor that ships with Borland C++) could easily remove the copyright information from the About box.
By embedding copyright information in the executable file as a simple text string, you'll protect yourself to a greater degree. Similarly, if you distribute object (OBJ) files to other developers so that they can use the functions you've developed, you may want to protect these files individually.
You might also consider the #pragma comment directivewhich
you can read about in the online helpan appropriate solution.
Unfortunately, the #pragma comment directive doesn't
work exactly as documented in the online help. In this article,
we'll show how you can use the undocumented #pragma
codestring directive to embed text in your executable and
object files as a means of copyright identification.
The most common use for the #pragma comment directive is to specify ordering for Library (LIB) files without updating the linker's response file. However, the online help implies that there are two other ways you can use this directive: to add a string to an application or to add a string to a single OBJ file.
According to the online help, to embed a text string in an OBJ
file, you simply add the line
#pragma comment(user, "Embedded String")
to the appropriate source file. What the online help doesn't tell you is that this line cannot be the first line in a given source file. It must follow another directive, a declaration, or a definition.
Similarly, the online help states that if you add
#pragma comment(exestr, "Embedded String")
to a source file, the compiler will place the string in a reserved area, and the linker will then include the string in the final EXE file. However, this doesn't seem to be the case, as the linker will always ignore this type of string when it builds the executable. In practice, the exestr and user versions of the #pragma comment directive behave identically.
Instead, you can use the #pragma codestring directive
to embed text strings in your OBJ and EXE files. For example,
if you add the line
#pragma codestring "Embedded String"
to a source file, the compiler will allocate a region of memory for the text Embedded String and treat it as unreferenced program data. Since the linker considers the text to be program data, it will always pass the text through to become part of the final executable file.
By the way, if you're concerned about these embedded strings
using up valuable memory space, don't worry. The embedded
text will obviously occupy some disk space. However, when the
operating system loads the application, it will ignore the string
(since the program doesn't use the data), and the string
won't use up application memory. Now let's create
a simple project that embeds text strings in both the OBJ file
and the EXE file.
To begin, launch the Borland C++ Integrated Development Environment (IDE). When the IDE's main window appears, choose New Project... from the Project menu, enter \CODESTRN\CODESTRN.IDE in the Project Path And Name entry field, choose EasyWin [.exe] from the Target Type list box, and click OK.
When the CODESTRN.IDE project window appears, right-click the codestrn [.def] node, choose Delete, and then click Yes when the IDE asks if you want to delete this project node. Repeat this process for the codestrn [.rc] node.
Next, double-click the codestrn [.cpp] node. (If this node doesn't exist, delete any default nodes and add this node man-ually.) When the editing window for this file appears, enter the code from Listing A.
Listing A: CODESTRN.CPP
#pragma codestring "Copyright SpencerSoft 1995" int main() { return 0; }
When you've finished entering the code, choose Build All from the Project menu. After the compiler has finished building the project, activate Program Manager and double-click the MS-DOS icon in the Main program group to open a DOS command line.
Enter cd \CODESTRN to make the new project's directory
current, and then enter
tdump codestrn.obj
to produce a report about the project's OBJ file. At the end of the report, you'll see the LEDATA structure, as shown in Figure A.
Figure A - At the end of the TDUMP report on the CODESTRN.OBJ file, you'll find the embedded text string.
Now, to create a summary of the CODESTRN.EXE file, enter the following
command:
tdump codestrn.exe -h codestrn.dmp
This command routes the output from the TDUMP diagnostic utility into a file named CODESTRN.DMP.
Return to the IDE, choose Open... from the File menu, and enter codestrn.dmp in the File Name entry field. Click OK to open the file.
When the editing window for this file appears, choose Find... from the Search menu, enter Copyright in the Text To Find entry field, and click OK. When the IDE locates the embedded text, you'll see it, as shown in Figure B.
Figure B - You can use the TDUMP utility to produce a hexadecimal report of the EXE file and confirm that your copyright notice is embedded in your application.
If you distribute your OBJ or EXE files through several channels,
you'll want to protect yourself to the greatest extent
possible. By using the #pragma codestring directive,
you can easily embed a copyright notice in both your OBJ files
and the resulting EXE files.
Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.