// unpacker.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <windows.h>
#include <fstream>
#include <iostream>
usingnamespace std;
typedefvoid* (__stdcall *UnpackFile)(unsignedchar*, int, LPTSTR, int);
int _tmain(int argc, _TCHAR* argv[])
{
LPTSTR header;
//Move this line and get a access violation on the _UnpackFile(filetounpack... line
staticunsignedchar *filetounpack; //Buffer to byte array with the file to unpack
int filelen; //variable to store the length of the file
HINSTANCE dllHandle; // Handle to DLL
UnpackFile _UnpackFile; // Function pointer
ifstream filetoread; //Stream class to read from files
static LPTSTR header2; //Buffer for the header 2nd
filetoread.open ("c:/projects/testfile.bin", ios::in | ios::binary|ios::ate);
filelen = filetoread.tellg(); //read the length
filetounpack = newunsignedchar [filelen]; //allocate space
filetoread.seekg (0, ios::beg); //set beginning
filetoread.read ((char *)filetounpack, filelen); //read the file into the buffer
filetoread.close(); //close the file
dllHandle = LoadLibrary(_T("unpacker.dll"));
if (dllHandle)
{
_UnpackFile = (UnpackFile)GetProcAddress(dllHandle, "UnpackFile");
if(_UnpackFile)
{
//header = new _TCHAR[filelen]; //Allocate memory for header
header2 = new _TCHAR[filelen]; //Allocate memory for header
void* tmp = _UnpackFile(filetounpack ,filelen ,header2 ,filelen);
delete[] filetounpack;
delete[] header;
delete[] header2;
}
else
{
std::cout << "Could not retrieve address function!" << std::endl;
}
FreeLibrary(dllHandle);
}
else
{
std::cout << "DLL Failed To Load!" << std::endl;
}
return 0;
}