Merging MinGW changes
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
/*
|
||||
* Source code of the functions inside our test DLL. Note that DllMain is
|
||||
* not required (it will be provided by the stub in libmingw32.a).
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int Add (int x, int y)
|
||||
{
|
||||
printf ("In add!\nx = %d\ny = %d\n", x, y);
|
||||
return (x + y);
|
||||
}
|
||||
|
||||
|
||||
double __attribute__((stdcall)) Sub (double x, double y)
|
||||
{
|
||||
printf ("In sub!\nx = %f\ny = %f\n", x, y);
|
||||
return (x - y);
|
||||
}
|
||||
|
||||
/*
|
||||
* Source code of the functions inside our test DLL. Note that DllMain is
|
||||
* not required (it will be provided by the stub in libmingw32.a).
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int Add (int x, int y)
|
||||
{
|
||||
printf ("In add!\nx = %d\ny = %d\n", x, y);
|
||||
return (x + y);
|
||||
}
|
||||
|
||||
|
||||
double __attribute__((stdcall)) Sub (double x, double y)
|
||||
{
|
||||
printf ("In sub!\nx = %f\ny = %f\n", x, y);
|
||||
return (x - y);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
EXPORTS
|
||||
Add
|
||||
Sub@16
|
||||
EXPORTS
|
||||
Add
|
||||
Sub@16
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
int Add (int x, int y);
|
||||
double __attribute__((stdcall)) Sub (double x, double y);
|
||||
|
||||
|
||||
int Add (int x, int y);
|
||||
double __attribute__((stdcall)) Sub (double x, double y);
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dll.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, k;
|
||||
double dk;
|
||||
|
||||
i = 10;
|
||||
j = 13;
|
||||
|
||||
k = Add(i, j);
|
||||
|
||||
printf ("%d + %d = %d\n", i, j, k);
|
||||
|
||||
dk = Sub(i, j);
|
||||
|
||||
printf ("%d - %d = %f\n", i, j, dk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dll.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, k;
|
||||
double dk;
|
||||
|
||||
i = 10;
|
||||
j = 13;
|
||||
|
||||
k = Add(i, j);
|
||||
|
||||
printf ("%d + %d = %d\n", i, j, k);
|
||||
|
||||
dk = Sub(i, j);
|
||||
|
||||
printf ("%d - %d = %f\n", i, j, dk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
In add!
|
||||
x = 10
|
||||
y = 13
|
||||
10 + 13 = 23
|
||||
In sub!
|
||||
x = 10
|
||||
y = 13
|
||||
10 - 13 = -3
|
||||
In add!
|
||||
x = 10
|
||||
y = 13
|
||||
10 + 13 = 23
|
||||
In sub!
|
||||
x = 10
|
||||
y = 13
|
||||
10 - 13 = -3
|
||||
|
@ -1,17 +1,17 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
ExportedFromExe ()
|
||||
{
|
||||
printf ("This output produced by ExportedFromExe.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf ("Hello, world\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
ExportedFromExe ()
|
||||
{
|
||||
printf ("This output produced by ExportedFromExe.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf ("Hello, world\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
EXPORTS
|
||||
ExportedFromExe
|
||||
EXPORTS
|
||||
ExportedFromExe
|
||||
|
@ -1,40 +1,40 @@
|
||||
/*
|
||||
* This version attempts to load dll.dll dynamically, get the address of the
|
||||
* Add function, and then call it.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
int (*Add)(int x, int y);
|
||||
|
||||
int main()
|
||||
{
|
||||
HINSTANCE hDll;
|
||||
int i, j, k;
|
||||
|
||||
hDll = LoadLibrary ("dll.dll");
|
||||
if (!hDll)
|
||||
{
|
||||
printf ("Error %d loading dll.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
if (!(Add = GetProcAddress (hDll, "Add")))
|
||||
{
|
||||
printf ("Error %d getting Add function.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
i = 10;
|
||||
j = 13;
|
||||
|
||||
k = Add(i, j);
|
||||
|
||||
printf ("i %d, j %d, k %d\n", i, j, k);
|
||||
|
||||
FreeLibrary (hDll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This version attempts to load dll.dll dynamically, get the address of the
|
||||
* Add function, and then call it.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
int (*Add)(int x, int y);
|
||||
|
||||
int main()
|
||||
{
|
||||
HINSTANCE hDll;
|
||||
int i, j, k;
|
||||
|
||||
hDll = LoadLibrary ("dll.dll");
|
||||
if (!hDll)
|
||||
{
|
||||
printf ("Error %d loading dll.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
if (!(Add = GetProcAddress (hDll, "Add")))
|
||||
{
|
||||
printf ("Error %d getting Add function.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
i = 10;
|
||||
j = 13;
|
||||
|
||||
k = Add(i, j);
|
||||
|
||||
printf ("i %d, j %d, k %d\n", i, j, k);
|
||||
|
||||
FreeLibrary (hDll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,47 +1,47 @@
|
||||
/*
|
||||
* This program attempts to load expexe.exe dynamically, get the address of the
|
||||
* ExportedFromExe function, and then call it.
|
||||
*
|
||||
* This example DOES NOT WORK! I don't know exactly what can be done, but
|
||||
* it simply seems that LoadLibrary refuses to load executables.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
int (*ExportedFromExe)();
|
||||
|
||||
int main()
|
||||
{
|
||||
HINSTANCE hDll;
|
||||
int i, j, k;
|
||||
|
||||
hDll = LoadLibrary ("expexe.exe");
|
||||
if (!hDll)
|
||||
{
|
||||
printf ("Error %d loading exe.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
if (!(ExportedFromExe = GetProcAddress (hDll, "ExportedFromExe")))
|
||||
{
|
||||
printf ("Error %d getting ExportedFromExe function.\n",
|
||||
GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExportedFromExe ();
|
||||
}
|
||||
|
||||
/* NOTE: Unlike a DLL the exe doesn't have an entry point which
|
||||
* initializes global objects and adds __do_global_dtors to
|
||||
* the atexit list. Thus it should be safe(?) to free the
|
||||
* library. Of course, this also makes it unsafe to use
|
||||
* executables at all in this manner.
|
||||
*/
|
||||
FreeLibrary (hDll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This program attempts to load expexe.exe dynamically, get the address of the
|
||||
* ExportedFromExe function, and then call it.
|
||||
*
|
||||
* This example DOES NOT WORK! I don't know exactly what can be done, but
|
||||
* it simply seems that LoadLibrary refuses to load executables.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
int (*ExportedFromExe)();
|
||||
|
||||
int main()
|
||||
{
|
||||
HINSTANCE hDll;
|
||||
int i, j, k;
|
||||
|
||||
hDll = LoadLibrary ("expexe.exe");
|
||||
if (!hDll)
|
||||
{
|
||||
printf ("Error %d loading exe.\n", GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
if (!(ExportedFromExe = GetProcAddress (hDll, "ExportedFromExe")))
|
||||
{
|
||||
printf ("Error %d getting ExportedFromExe function.\n",
|
||||
GetLastError());
|
||||
exit (-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExportedFromExe ();
|
||||
}
|
||||
|
||||
/* NOTE: Unlike a DLL the exe doesn't have an entry point which
|
||||
* initializes global objects and adds __do_global_dtors to
|
||||
* the atexit list. Thus it should be safe(?) to free the
|
||||
* library. Of course, this also makes it unsafe to use
|
||||
* executables at all in this manner.
|
||||
*/
|
||||
FreeLibrary (hDll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,39 +1,39 @@
|
||||
This directory contains two examples of building DLLs. The exe.c and dll.c
|
||||
files are used to build a very simple example DLL with a function that
|
||||
adds two numbers together (and prints some text at the same time). The
|
||||
exe.c program links to the DLL and prints the results of the function
|
||||
call.
|
||||
|
||||
The C++ example "silly" is more interesting because it involves a DLL which
|
||||
contains the code for a C++ class. The CSilly class has all of its code in
|
||||
the sillydll.cpp source file, which is used to build the silly.dll. The
|
||||
silly.cpp source code builds the main silly.exe executable which makes a
|
||||
dynamic instance of the object and calls its member functions.
|
||||
|
||||
The C++ silly.def file was generated by doing a nm of sillydll.o after it
|
||||
was generated and then getting the symbol names from that. Removing the
|
||||
leading underscore produces the appropriate name to include in the EXPORTS
|
||||
section. Notice there are a few weird functions.
|
||||
|
||||
Since there are now several different versions of the GNU compiler capable
|
||||
of doing this, and they each seem to have different requirements for exports
|
||||
for classes, it has gotten kind of messy. The silly.def file here is for
|
||||
use with the native Mingw32 build of the EGCS version of GCC. The silly.def.old
|
||||
file was the def file I used when I was using Jan-Jaap's Mingw32 native port
|
||||
of GCC. The Cygnus version is different again, if I recall correctly, but I
|
||||
don't have it hanging around anymore.
|
||||
|
||||
The jamfile builds all the components from the raw sources.
|
||||
|
||||
The expected output of exe.exe and silly.exe are in the files exe.exp
|
||||
and silly.exp.
|
||||
|
||||
|
||||
The source code in this directory is in the PUBLIC DOMAIN and can be
|
||||
used or abused as you see fit. There is NO WARRANTY for this code,
|
||||
including (but not limited to) implied warranties of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
|
||||
|
||||
This directory contains two examples of building DLLs. The exe.c and dll.c
|
||||
files are used to build a very simple example DLL with a function that
|
||||
adds two numbers together (and prints some text at the same time). The
|
||||
exe.c program links to the DLL and prints the results of the function
|
||||
call.
|
||||
|
||||
The C++ example "silly" is more interesting because it involves a DLL which
|
||||
contains the code for a C++ class. The CSilly class has all of its code in
|
||||
the sillydll.cpp source file, which is used to build the silly.dll. The
|
||||
silly.cpp source code builds the main silly.exe executable which makes a
|
||||
dynamic instance of the object and calls its member functions.
|
||||
|
||||
The C++ silly.def file was generated by doing a nm of sillydll.o after it
|
||||
was generated and then getting the symbol names from that. Removing the
|
||||
leading underscore produces the appropriate name to include in the EXPORTS
|
||||
section. Notice there are a few weird functions.
|
||||
|
||||
Since there are now several different versions of the GNU compiler capable
|
||||
of doing this, and they each seem to have different requirements for exports
|
||||
for classes, it has gotten kind of messy. The silly.def file here is for
|
||||
use with the native Mingw32 build of the EGCS version of GCC. The silly.def.old
|
||||
file was the def file I used when I was using Jan-Jaap's Mingw32 native port
|
||||
of GCC. The Cygnus version is different again, if I recall correctly, but I
|
||||
don't have it hanging around anymore.
|
||||
|
||||
The jamfile builds all the components from the raw sources.
|
||||
|
||||
The expected output of exe.exe and silly.exe are in the files exe.exp
|
||||
and silly.exp.
|
||||
|
||||
|
||||
The source code in this directory is in the PUBLIC DOMAIN and can be
|
||||
used or abused as you see fit. There is NO WARRANTY for this code,
|
||||
including (but not limited to) implied warranties of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
|
||||
|
||||
|
@ -1,55 +1,55 @@
|
||||
//
|
||||
// C++ test of a dll which contains a C++ class.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Interface of class.
|
||||
#include "silly.h"
|
||||
|
||||
#ifdef DERIVED_TEST
|
||||
// Here is a derived class too.
|
||||
class CMoreSilly : public CSilly
|
||||
{
|
||||
public:
|
||||
CMoreSilly (char* szNewName) : CSilly (szNewName) {};
|
||||
~CMoreSilly ();
|
||||
|
||||
WhatsYourName();
|
||||
};
|
||||
|
||||
CMoreSilly::
|
||||
~CMoreSilly ()
|
||||
{
|
||||
printf ("In CMoreSilly \"%s\" destructor!\n", szName);
|
||||
}
|
||||
|
||||
CMoreSilly::
|
||||
WhatsYourName ()
|
||||
{
|
||||
printf ("I'm more silly and my name is \"%s\"\n", szName);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
CSilly* psilly = new CSilly("silly");
|
||||
|
||||
psilly->WhatsYourName();
|
||||
psilly->Poke(); // Poke him, he should say "Ouch!"
|
||||
psilly->Stab(4); // Stab him four times he should say "Ugh!!!!"
|
||||
|
||||
delete psilly;
|
||||
|
||||
#ifdef DERIVED_TEST
|
||||
psilly = new CMoreSilly("more silly");
|
||||
psilly->WhatsYourName();
|
||||
psilly->Stab(5);
|
||||
delete psilly;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// C++ test of a dll which contains a C++ class.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Interface of class.
|
||||
#include "silly.h"
|
||||
|
||||
#ifdef DERIVED_TEST
|
||||
// Here is a derived class too.
|
||||
class CMoreSilly : public CSilly
|
||||
{
|
||||
public:
|
||||
CMoreSilly (char* szNewName) : CSilly (szNewName) {};
|
||||
~CMoreSilly ();
|
||||
|
||||
WhatsYourName();
|
||||
};
|
||||
|
||||
CMoreSilly::
|
||||
~CMoreSilly ()
|
||||
{
|
||||
printf ("In CMoreSilly \"%s\" destructor!\n", szName);
|
||||
}
|
||||
|
||||
CMoreSilly::
|
||||
WhatsYourName ()
|
||||
{
|
||||
printf ("I'm more silly and my name is \"%s\"\n", szName);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
CSilly* psilly = new CSilly("silly");
|
||||
|
||||
psilly->WhatsYourName();
|
||||
psilly->Poke(); // Poke him, he should say "Ouch!"
|
||||
psilly->Stab(4); // Stab him four times he should say "Ugh!!!!"
|
||||
|
||||
delete psilly;
|
||||
|
||||
#ifdef DERIVED_TEST
|
||||
psilly = new CMoreSilly("more silly");
|
||||
psilly->WhatsYourName();
|
||||
psilly->Stab(5);
|
||||
delete psilly;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
EXPORTS
|
||||
DllMain@12
|
||||
Poke__6CSilly
|
||||
Stab__6CSillyi
|
||||
WhatsYourName__6CSilly
|
||||
_$_6CSilly
|
||||
__6CSilly
|
||||
__6CSillyPc
|
||||
__tf6CSilly
|
||||
__ti6CSilly
|
||||
_vt$6CSilly
|
||||
EXPORTS
|
||||
DllMain@12
|
||||
Poke__6CSilly
|
||||
Stab__6CSillyi
|
||||
WhatsYourName__6CSilly
|
||||
_$_6CSilly
|
||||
__6CSilly
|
||||
__6CSillyPc
|
||||
__tf6CSilly
|
||||
__ti6CSilly
|
||||
_vt$6CSilly
|
||||
|
@ -1,8 +1,8 @@
|
||||
I'm silly.
|
||||
Ouch!
|
||||
Ugh!!!!
|
||||
In CSilly destructor.
|
||||
I'm more silly and my name is "more silly"
|
||||
Ugh!!!!!
|
||||
In CMoreSilly "more silly" destructor!
|
||||
In CSilly destructor.
|
||||
I'm silly.
|
||||
Ouch!
|
||||
Ugh!!!!
|
||||
In CSilly destructor.
|
||||
I'm more silly and my name is "more silly"
|
||||
Ugh!!!!!
|
||||
In CMoreSilly "more silly" destructor!
|
||||
In CSilly destructor.
|
||||
|
@ -1,27 +1,27 @@
|
||||
|
||||
#define DERIVED_TEST 1
|
||||
|
||||
class CSilly
|
||||
{
|
||||
protected:
|
||||
char* szName;
|
||||
|
||||
public:
|
||||
CSilly();
|
||||
CSilly(char* szName);
|
||||
#ifdef DERIVED_TEST
|
||||
virtual ~CSilly();
|
||||
#else
|
||||
~CSilly();
|
||||
#endif
|
||||
|
||||
Poke ();
|
||||
Stab (int nTimes);
|
||||
#ifdef DERIVED_TEST
|
||||
virtual WhatsYourName ();
|
||||
#else
|
||||
WhatsYourName ();
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define DERIVED_TEST 1
|
||||
|
||||
class CSilly
|
||||
{
|
||||
protected:
|
||||
char* szName;
|
||||
|
||||
public:
|
||||
CSilly();
|
||||
CSilly(char* szName);
|
||||
#ifdef DERIVED_TEST
|
||||
virtual ~CSilly();
|
||||
#else
|
||||
~CSilly();
|
||||
#endif
|
||||
|
||||
Poke ();
|
||||
Stab (int nTimes);
|
||||
#ifdef DERIVED_TEST
|
||||
virtual WhatsYourName ();
|
||||
#else
|
||||
WhatsYourName ();
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,107 +1,107 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define STREAMS_VERSION
|
||||
#endif
|
||||
|
||||
#if defined(STREAMS_VERSION)
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
#include "silly.h"
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CSilly::
|
||||
CSilly()
|
||||
{
|
||||
szName = NULL;
|
||||
}
|
||||
|
||||
CSilly::
|
||||
CSilly(char* new_szName)
|
||||
{
|
||||
szName = new char[strlen(new_szName)+1];
|
||||
|
||||
if (szName)
|
||||
{
|
||||
strcpy (szName, new_szName);
|
||||
}
|
||||
}
|
||||
|
||||
CSilly::
|
||||
~CSilly()
|
||||
{
|
||||
printf ("In CSilly destructor.\n");
|
||||
if (szName)
|
||||
{
|
||||
delete szName;
|
||||
}
|
||||
}
|
||||
|
||||
CSilly::
|
||||
Poke ()
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("Ouch!\n");
|
||||
#else
|
||||
cout << "Ouch!" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
CSilly::
|
||||
Stab (int nTimes)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("Ugh");
|
||||
#else
|
||||
cout << "Ugh";
|
||||
#endif
|
||||
|
||||
int i;
|
||||
for (i = 0; i < nTimes; i++)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
putchar('!');
|
||||
#else
|
||||
cout << '!' ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef STREAMS_VERSION
|
||||
putchar('\n');
|
||||
#else
|
||||
cout << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
CSilly::
|
||||
WhatsYourName ()
|
||||
{
|
||||
if (szName)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("I'm %s.\n", szName);
|
||||
#else
|
||||
cout << "I'm " << szName << "." << endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("I have no name.\n");
|
||||
#else
|
||||
cout << "I have no name." << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define STREAMS_VERSION
|
||||
#endif
|
||||
|
||||
#if defined(STREAMS_VERSION)
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
#include "silly.h"
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CSilly::
|
||||
CSilly()
|
||||
{
|
||||
szName = NULL;
|
||||
}
|
||||
|
||||
CSilly::
|
||||
CSilly(char* new_szName)
|
||||
{
|
||||
szName = new char[strlen(new_szName)+1];
|
||||
|
||||
if (szName)
|
||||
{
|
||||
strcpy (szName, new_szName);
|
||||
}
|
||||
}
|
||||
|
||||
CSilly::
|
||||
~CSilly()
|
||||
{
|
||||
printf ("In CSilly destructor.\n");
|
||||
if (szName)
|
||||
{
|
||||
delete szName;
|
||||
}
|
||||
}
|
||||
|
||||
CSilly::
|
||||
Poke ()
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("Ouch!\n");
|
||||
#else
|
||||
cout << "Ouch!" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
CSilly::
|
||||
Stab (int nTimes)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("Ugh");
|
||||
#else
|
||||
cout << "Ugh";
|
||||
#endif
|
||||
|
||||
int i;
|
||||
for (i = 0; i < nTimes; i++)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
putchar('!');
|
||||
#else
|
||||
cout << '!' ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef STREAMS_VERSION
|
||||
putchar('\n');
|
||||
#else
|
||||
cout << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
CSilly::
|
||||
WhatsYourName ()
|
||||
{
|
||||
if (szName)
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("I'm %s.\n", szName);
|
||||
#else
|
||||
cout << "I'm " << szName << "." << endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef STREAMS_VERSION
|
||||
printf ("I have no name.\n");
|
||||
#else
|
||||
cout << "I have no name." << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user