1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// LoadTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include "OSFDlg.h"
#include <assert.h>
using namespace std;
template <typename Target, typename Source>
Target lexical_cast(Source source)
{
Target target;
std::ostringstream os;
os << source;
std::istringstream is(os.str());
is >> target;
return target;
}
struct Save
{
wchar_t *LevelName;
float X, Y, Z;
};
wchar_t LoadDiag()
{
//Filter
TCHAR szFilter[] = TEXT("Save Files (*.SAV)\0*.sav\0");
//Default Extension
TCHAR szDefExtension[] = TEXT("sav\0");
COSFDialog LoadDiag;
if(LoadDiag.FileOpenDlg(szFilter, szDefExtension, TEXT("Load Game"), false))
return (wchar_t)LoadDiag.GetFileName();
}
wchar_t* ReadLine(wifstream *Stream)
{
wchar_t *Line = new wchar_t[256];
wchar_t ControlChar = '0';
int i = 0;
while(ControlChar != '\n')
{
ControlChar = Stream->get();
wcout << ControlChar;
Line[i] = ControlChar;
i++;
if(i == 256)
break;
}
return Line;
}
__declspec(dllexport) Save* LoadGame(wchar_t* LoadPath)
{
wifstream LoadStream(LoadPath, ios::in);
wchar_t X;
wchar_t Y;
wchar_t Z;
static Save NewSave;
NewSave.LevelName = new wchar_t[100];
NewSave.LevelName = ReadLine(&LoadStream);
LoadStream >> X;
NewSave.X = lexical_cast<float, wchar_t>(X);
LoadStream >> Y;
NewSave.Y = lexical_cast<float, wchar_t>(Y);
LoadStream >> Z;
NewSave.Z = lexical_cast<float, wchar_t>(Z);
/*LoadStream >> NewSave.X;
LoadStream >> NewSave.Y;
LoadStream >> NewSave.Z;*/
LoadStream.close();
MessageBox(NULL, (LPCWSTR)NewSave.LevelName, TEXT("LoadGame()"), MB_OKCANCEL);
return &NewSave;
}
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t SavePath = LoadDiag();
Save *Sav = LoadGame(&SavePath);
assert(Sav);
return 0;
}
|