Add windows libs
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
template <class A, class B>
|
||||
class Pair
|
||||
{
|
||||
private:
|
||||
A index;
|
||||
B value;
|
||||
public:
|
||||
Pair(A aa, B bb):index(aa),value(bb) {}
|
||||
void display()
|
||||
{
|
||||
cout << index << ' ' << value << endl;
|
||||
}
|
||||
bool operator>(const Pair<A,B>& p)
|
||||
{ return index>p.index;}
|
||||
};
|
||||
|
||||
template <class B>
|
||||
class Pair<char*, B>
|
||||
{
|
||||
private:
|
||||
char* index;
|
||||
B value;
|
||||
public:
|
||||
Pair(char* aa, B bb):value(bb)
|
||||
{index = new char[strlen(aa)]; strcpy(index,aa);}
|
||||
void display()
|
||||
{
|
||||
cout << index << ' ' << value << endl;
|
||||
}
|
||||
bool operator>(const Pair<char*, B>& p)
|
||||
{ return ( strcmp(index,p.index) > 0);}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Pair<double,int> first(2.2,3);
|
||||
first.display();
|
||||
Pair<double,int> second(2.1,4);
|
||||
second.display();
|
||||
if (first > second)
|
||||
cout << "first is greater" << endl;
|
||||
else
|
||||
cout << "first is not greater" << endl;
|
||||
Pair<char*,int> third("Hello",4);
|
||||
third.display();
|
||||
Pair<char*,int> fourth("World",5);
|
||||
fourth.display();
|
||||
if (third > fourth)
|
||||
cout << "third is greater" << endl;
|
||||
else
|
||||
cout << "third is not greater" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
cl /EHsc conformance.cpp
|
||||
conformance
|
@@ -0,0 +1,69 @@
|
||||
|
||||
#using <mscorlib.dll>
|
||||
#using <System.dll>
|
||||
|
||||
using namespace System;
|
||||
|
||||
#using <System.Xml.dll>
|
||||
using namespace System::Xml;
|
||||
|
||||
#using <System.Drawing.dll>
|
||||
using namespace System::Drawing;
|
||||
|
||||
using namespace System::Diagnostics;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
XmlDocument* xmlDoc = new XmlDocument();
|
||||
|
||||
try
|
||||
{
|
||||
xmlDoc->Load(S"sample.xml");
|
||||
Console::WriteLine(S"Document loaded ok." );
|
||||
XmlNodeList* items = xmlDoc->GetElementsByTagName(S"Item");
|
||||
double total = 0;
|
||||
long numitems = items->Count;
|
||||
for (int i=0;i<numitems;i++)
|
||||
{
|
||||
XmlNode* item = items->Item(i);
|
||||
double price = Double::Parse(item->Attributes->GetNamedItem(S"Price")->get_Value());
|
||||
double qty = Double::Parse(item->Attributes->GetNamedItem(S"Quantity")->get_Value());
|
||||
total += price * qty;
|
||||
}
|
||||
Console::WriteLine(S"Purchase Order total is ${0}", __box(total));
|
||||
}
|
||||
catch (Exception *e)
|
||||
{
|
||||
Console::WriteLine(S"problem loading XML");
|
||||
Console::WriteLine(e->Message);
|
||||
}
|
||||
try
|
||||
{
|
||||
Image* image = Image::FromFile(S"largepicture.jpg");
|
||||
Image* thumbnail = image->GetThumbnailImage(100,100,0,0);
|
||||
thumbnail->Save(S"thumbnail.jpg",Imaging::ImageFormat::Jpeg);
|
||||
Console::WriteLine(S"Thumbnail created");
|
||||
}
|
||||
catch (Exception* e)
|
||||
{
|
||||
// out of memory exception thrown for bad format
|
||||
Console::WriteLine(S"Image file not found or invalid format");
|
||||
Console::WriteLine(e->Message);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (! EventLog::SourceExists(S"SDKSample") )
|
||||
EventLog::CreateEventSource(S"SDKSample",S"SDKSampleLog");
|
||||
EventLog::WriteEntry(S"SDKSample",S"The sample has been run.", EventLogEntryType::Information);
|
||||
Console::WriteLine(S"Event logged");
|
||||
}
|
||||
catch (Exception* e)
|
||||
{
|
||||
Console::WriteLine(S"problem creating or writing to event log");
|
||||
Console::WriteLine(e->Message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
cl /clr framework.cpp
|
||||
framework
|
Binary file not shown.
After Width: | Height: | Size: 364 KiB |
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PurchaseOrder>
|
||||
<Customer id="123"/>
|
||||
<Item SKU="1234" Price="1.23" Quantity="1"/>
|
||||
<Item SKU="1235" Price="4.56" Quantity="2"/>
|
||||
</PurchaseOrder>
|
@@ -0,0 +1 @@
|
||||
cl /O2 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W4 /Wp64 /TP /EHsc /Zi /G7 GL-G7.cpp module.cpp
|
@@ -0,0 +1 @@
|
||||
cl /O2 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W4 /Wp64 /TP /EHsc /Zi /G7 /arch:SSE2 GL-G7.cpp module.cpp
|
@@ -0,0 +1,192 @@
|
||||
// GL-G7.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// _ReturnAddress should be prototyped before use
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
void * _ReturnAddress(void);
|
||||
|
||||
#pragma intrinsic(_ReturnAddress)
|
||||
|
||||
//prototyping here to save #include of windows.h -- functions are in kernel32
|
||||
|
||||
typedef unsigned long DWORD;
|
||||
typedef void *HANDLE;
|
||||
typedef long LONG;
|
||||
typedef int BOOL;
|
||||
typedef __int64 LONGLONG;
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
DWORD LowPart;
|
||||
LONG HighPart;
|
||||
};
|
||||
struct {
|
||||
DWORD LowPart;
|
||||
LONG HighPart;
|
||||
} u;
|
||||
LONGLONG QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
|
||||
#define WINBASEAPI
|
||||
#define WINAPI __stdcall
|
||||
#define IN
|
||||
#define OUT
|
||||
#define VOID void
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
WINBASEAPI BOOL WINAPI QueryPerformanceCounter(OUT LARGE_INTEGER *lpPerformanceCount);
|
||||
WINBASEAPI BOOL WINAPI QueryPerformanceFrequency(OUT LARGE_INTEGER *lpFrequency);
|
||||
WINBASEAPI DWORD WINAPI SetThreadAffinityMask(IN HANDLE hThread,IN DWORD dwThreadAffinityMask);
|
||||
WINBASEAPI HANDLE WINAPI GetCurrentThread(VOID);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
//end of replacement for windows.h
|
||||
|
||||
|
||||
void* inlineReturnAddress; // set in Add()
|
||||
int Add(int a, int b); // implementation in module.cpp
|
||||
|
||||
void DisplayAdd(int a, int b)
|
||||
{
|
||||
cout << a << " + " << b << " = " << a + b << endl;
|
||||
cout << "Return address from " << __FUNCTION__ << " " << _ReturnAddress() << endl;
|
||||
}
|
||||
|
||||
void Test1()
|
||||
{
|
||||
DisplayAdd(1,2);
|
||||
cout << "1 + 2 = " << Add(1,2) << endl;
|
||||
|
||||
cout << "Return address from Add " << inlineReturnAddress << endl;
|
||||
|
||||
cout << "Return address from " << __FUNCTION__ << " " << _ReturnAddress() << endl;
|
||||
}
|
||||
|
||||
|
||||
#define INT_ARRAY_LEN 100000
|
||||
int intarray[INT_ARRAY_LEN];
|
||||
int intCalculate()
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
for (int i = 1; i < INT_ARRAY_LEN; i++)
|
||||
{
|
||||
total += intarray[i-1]*7;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
void Test2()
|
||||
{
|
||||
int var1 = 2;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < INT_ARRAY_LEN; i++)
|
||||
{
|
||||
intarray[i] = i*5;
|
||||
var1 += 2;
|
||||
}
|
||||
|
||||
LARGE_INTEGER start, end;
|
||||
LARGE_INTEGER freq;
|
||||
|
||||
SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&start);
|
||||
double total = 0;
|
||||
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
total += intCalculate();
|
||||
}
|
||||
|
||||
QueryPerformanceCounter(&end);
|
||||
|
||||
cout << "Total = " << total << endl;
|
||||
|
||||
cout << (end.QuadPart - start.QuadPart)/(double)freq.QuadPart << " seconds" << endl;
|
||||
}
|
||||
|
||||
#define ARRAY_LEN 10000
|
||||
double array[ARRAY_LEN];
|
||||
|
||||
double Calculate()
|
||||
{
|
||||
double total = 0;
|
||||
|
||||
for (int i = 1; i < ARRAY_LEN; i++)
|
||||
{
|
||||
total += array[i-1]*array[i];
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
void Test3()
|
||||
{
|
||||
double var1 = 2;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_LEN; i++)
|
||||
{
|
||||
array[i] = var1;
|
||||
var1 += .012;
|
||||
}
|
||||
|
||||
LARGE_INTEGER start, end;
|
||||
LARGE_INTEGER freq;
|
||||
|
||||
SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&start);
|
||||
double total = 0;
|
||||
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
total += Calculate();
|
||||
}
|
||||
|
||||
QueryPerformanceCounter(&end);
|
||||
|
||||
cout << "Total = " << total << endl;
|
||||
|
||||
cout << (end.QuadPart - start.QuadPart)/(double)freq.QuadPart << " seconds" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
int test = atoi(argv[1]);
|
||||
switch (test)
|
||||
{
|
||||
case 1:
|
||||
Test1();
|
||||
break;
|
||||
case 2:
|
||||
Test2();
|
||||
break;
|
||||
case 3:
|
||||
Test3();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "usage: gl-g7 num1 num2" << endl;
|
||||
cout << "num1 is 1 through 3." << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1 @@
|
||||
cl /O2 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W4 /Wp64 /TP /EHsc /Zi /GL GL-G7.cpp module.cpp
|
Binary file not shown.
@@ -0,0 +1 @@
|
||||
cl /O2 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W4 /Wp64 /TP /EHsc /Zi GL-G7.cpp module.cpp
|
@@ -0,0 +1,16 @@
|
||||
extern void *inlineReturnAddress;
|
||||
|
||||
// _ReturnAddress should be prototyped before use
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
void * _ReturnAddress(void);
|
||||
|
||||
#pragma intrinsic(_ReturnAddress)
|
||||
|
||||
int Add(int a, int b)
|
||||
{
|
||||
inlineReturnAddress = _ReturnAddress();
|
||||
return a+b;
|
||||
}
|
||||
|
@@ -0,0 +1,135 @@
|
||||
// GS-RTC.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// will get a runtime error with /RTCs and with /GS because return address is compromised as well as
|
||||
// other stack variables
|
||||
void Test1()
|
||||
{
|
||||
char buffer1[100];
|
||||
|
||||
for (int i=0 ; i < 200; i++)
|
||||
{
|
||||
buffer1[i] = 'a';
|
||||
}
|
||||
|
||||
buffer1[sizeof(buffer1)-1] = 0;
|
||||
|
||||
cout << buffer1 << endl;
|
||||
}
|
||||
|
||||
// will get a runtime error with /RTCs, but not /GS because return address not compromised, only other
|
||||
// stack variables
|
||||
void Test2()
|
||||
{
|
||||
char buffer1[100];
|
||||
char buffer2[100];
|
||||
|
||||
buffer1[0] = 0;
|
||||
|
||||
for (int i=0 ; i <= sizeof(buffer2); i++)
|
||||
{
|
||||
buffer2[i] = 'a';
|
||||
}
|
||||
|
||||
buffer2[sizeof(buffer2)-1] = 0;
|
||||
|
||||
cout << buffer2 << '-' << buffer1 << endl;
|
||||
}
|
||||
|
||||
// underrun buffer 3 - caught by RTCs
|
||||
void Test3()
|
||||
{
|
||||
char buffer1[100];
|
||||
char buffer2[100];
|
||||
|
||||
memset(buffer1,'a',sizeof(buffer1)-1);
|
||||
buffer1[sizeof(buffer1)-1]=0;
|
||||
memset(buffer2,'b',sizeof(buffer2)-1);
|
||||
buffer2[sizeof(buffer2)-1]=0;
|
||||
|
||||
*(buffer1-1) = 'c';
|
||||
cout << buffer1 << endl;
|
||||
cout << buffer2 << endl;
|
||||
}
|
||||
|
||||
// show starting values with /RTCs
|
||||
void Test4()
|
||||
{
|
||||
unsigned int var;
|
||||
|
||||
cout << hex << var;
|
||||
}
|
||||
|
||||
// truncate an integer into a char (/RTCc)
|
||||
void Test5(int value)
|
||||
{
|
||||
unsigned char ch;
|
||||
ch = (unsigned char)value;
|
||||
}
|
||||
|
||||
// Use uninitialized variables (/RTCu)
|
||||
void Test6(int value)
|
||||
{
|
||||
int uninitialized;
|
||||
int var;
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case 3:
|
||||
uninitialized = 4;
|
||||
case 2:
|
||||
var = 5 * uninitialized;
|
||||
break;
|
||||
case 1:
|
||||
int* var2 = &uninitialized;
|
||||
var = 5 * uninitialized;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc > 1) {
|
||||
int test = atoi(argv[1]);
|
||||
int value = 0;
|
||||
if (argc > 2)
|
||||
{
|
||||
value = atoi(argv[2]);
|
||||
}
|
||||
switch (test)
|
||||
{
|
||||
case 1:
|
||||
Test1();
|
||||
break;
|
||||
case 2:
|
||||
Test2();
|
||||
break;
|
||||
case 3:
|
||||
Test3();
|
||||
break;
|
||||
case 4:
|
||||
Test4();
|
||||
break;
|
||||
case 5:
|
||||
Test5(value);
|
||||
break;
|
||||
case 6:
|
||||
Test6(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "usage: gs-rtc num1 num2" << endl;
|
||||
cout << "num1 is 1 through 6. Tests 5 and 6 require an integer parameter, default 0" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
cl /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /ML /GS /W4 /Wp64 /TP /EHsc GS-RTC.cpp
|
@@ -0,0 +1 @@
|
||||
cl /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W3 /Wp64 /TP /EHsc /ZI GS-RTC.cpp
|
@@ -0,0 +1 @@
|
||||
cl /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W3 /Wp64 /TP /ZI /EHsc /RTCc GS-RTC.cpp
|
@@ -0,0 +1 @@
|
||||
cl /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W3 /Wp64 /TP /ZI /EHsc /RTCs GS-RTC.cpp
|
@@ -0,0 +1 @@
|
||||
cl /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /MLd /W4 /Wp64 /TP /ZI /EHsc /RTCu GS-RTC.cpp
|
Binary file not shown.
Reference in New Issue
Block a user