pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/fancycode/MemoryModule/commit/135337380ae04358c06d50d6c7f9b424deab19b4

/> added sample project · fancycode/MemoryModule@1353373 · GitHub
Skip to content

Commit 1353373

Browse files
committed
added sample project
1 parent cc38494 commit 1353373

8 files changed

Lines changed: 396 additions & 0 deletions

File tree

example/DllLoader/DllLoader.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#define WIN32_LEAN_AND_MEAN
2+
3+
#include <windows.h>
4+
#include <stdio.h>
5+
#include <malloc.h>
6+
7+
#include "../../MemoryModule.h"
8+
9+
typedef int (*addNumberProc)(int, int);
10+
11+
#define DLL_FILE "..\\..\\SampleDLL\\Debug\\SampleDLL.dll"
12+
13+
void LoadFromFile(void)
14+
{
15+
addNumberProc addNumber;
16+
HINSTANCE handle = LoadLibrary(DLL_FILE);
17+
if (handle == INVALID_HANDLE_VALUE)
18+
return;
19+
20+
addNumber = (addNumberProc)GetProcAddress(handle, "addNumbers");
21+
printf("From file: %d\n", addNumber(1, 2));
22+
FreeLibrary(handle);
23+
}
24+
25+
void LoadFromMemory(void)
26+
{
27+
FILE *fp;
28+
unsigned char *data=NULL;
29+
size_t size;
30+
HMEMORYMODULE module;
31+
addNumberProc addNumber;
32+
33+
fp = fopen(DLL_FILE, "rb");
34+
if (fp == NULL)
35+
{
36+
printf("Can't open DLL file \"%s\".", DLL_FILE);
37+
goto exit;
38+
}
39+
40+
fseek(fp, 0, SEEK_END);
41+
size = ftell(fp);
42+
data = (unsigned char *)malloc(size);
43+
fseek(fp, 0, SEEK_SET);
44+
fread(data, 1, size, fp);
45+
fclose(fp);
46+
47+
module = MemoryLoadLibrary(data, size);
48+
if (module == NULL)
49+
{
50+
printf("Can't load library from memory.\n");
51+
goto exit;
52+
}
53+
54+
addNumber = (addNumberProc)MemoryGetProcAddress(module, "addNumbers");
55+
printf("From memory: %d\n", addNumber(1, 2));
56+
MemoryFreeLibrary(module);
57+
58+
exit:
59+
if (data)
60+
free(data);
61+
}
62+
63+
int main(int argc, char* argv[])
64+
{
65+
LoadFromFile();
66+
printf("\n\n");
67+
LoadFromMemory();
68+
return 0;
69+
}
70+

example/DllLoader/DllLoader.vcproj

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="Windows-1252"?>
2+
<VisualStudioProject
3+
ProjectType="Visual C++"
4+
Version="7.10"
5+
Name="DllLoader"
6+
ProjectGUID="{D0226BB5-3A02-4C91-893A-F36567AED5C5}"
7+
Keyword="Win32Proj">
8+
<Platforms>
9+
<Platform
10+
Name="Win32"/>
11+
</Platforms>
12+
<Configurations>
13+
<Configuration
14+
Name="Debug|Win32"
15+
OutputDirectory="Debug"
16+
IntermediateDirectory="Debug"
17+
ConfigurationType="1"
18+
CharacterSet="2">
19+
<Tool
20+
Name="VCCLCompilerTool"
21+
Optimization="0"
22+
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
23+
MinimalRebuild="TRUE"
24+
BasicRuntimeChecks="3"
25+
RuntimeLibrary="5"
26+
UsePrecompiledHeader="0"
27+
WarningLevel="3"
28+
Detect64BitPortabilityProblems="TRUE"
29+
DebugInformationFormat="4"/>
30+
<Tool
31+
Name="VCCustomBuildTool"/>
32+
<Tool
33+
Name="VCLinkerTool"
34+
OutputFile="$(OutDir)/DllLoader.exe"
35+
LinkIncremental="2"
36+
GenerateDebugInformation="TRUE"
37+
ProgramDatabaseFile="$(OutDir)/DllLoader.pdb"
38+
SubSystem="1"
39+
TargetMachine="1"/>
40+
<Tool
41+
Name="VCMIDLTool"/>
42+
<Tool
43+
Name="VCPostBuildEventTool"/>
44+
<Tool
45+
Name="VCPreBuildEventTool"/>
46+
<Tool
47+
Name="VCPreLinkEventTool"/>
48+
<Tool
49+
Name="VCResourceCompilerTool"/>
50+
<Tool
51+
Name="VCWebServiceProxyGeneratorTool"/>
52+
<Tool
53+
Name="VCXMLDataGeneratorTool"/>
54+
<Tool
55+
Name="VCWebDeploymentTool"/>
56+
<Tool
57+
Name="VCManagedWrapperGeneratorTool"/>
58+
<Tool
59+
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
60+
</Configuration>
61+
<Configuration
62+
Name="Release|Win32"
63+
OutputDirectory="Release"
64+
IntermediateDirectory="Release"
65+
ConfigurationType="1"
66+
CharacterSet="2">
67+
<Tool
68+
Name="VCCLCompilerTool"
69+
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
70+
RuntimeLibrary="4"
71+
UsePrecompiledHeader="0"
72+
WarningLevel="3"
73+
Detect64BitPortabilityProblems="TRUE"
74+
DebugInformationFormat="3"/>
75+
<Tool
76+
Name="VCCustomBuildTool"/>
77+
<Tool
78+
Name="VCLinkerTool"
79+
OutputFile="$(OutDir)/DllLoader.exe"
80+
LinkIncremental="1"
81+
GenerateDebugInformation="TRUE"
82+
SubSystem="1"
83+
OptimizeReferences="2"
84+
EnableCOMDATFolding="2"
85+
TargetMachine="1"/>
86+
<Tool
87+
Name="VCMIDLTool"/>
88+
<Tool
89+
Name="VCPostBuildEventTool"/>
90+
<Tool
91+
Name="VCPreBuildEventTool"/>
92+
<Tool
93+
Name="VCPreLinkEventTool"/>
94+
<Tool
95+
Name="VCResourceCompilerTool"/>
96+
<Tool
97+
Name="VCWebServiceProxyGeneratorTool"/>
98+
<Tool
99+
Name="VCXMLDataGeneratorTool"/>
100+
<Tool
101+
Name="VCWebDeploymentTool"/>
102+
<Tool
103+
Name="VCManagedWrapperGeneratorTool"/>
104+
<Tool
105+
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
106+
</Configuration>
107+
</Configurations>
108+
<References>
109+
</References>
110+
<Files>
111+
<Filter
112+
Name="Quelldateien"
113+
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
114+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
115+
<File
116+
RelativePath=".\DllLoader.cpp">
117+
</File>
118+
<File
119+
RelativePath="..\..\MemoryModule.c">
120+
</File>
121+
</Filter>
122+
<Filter
123+
Name="Headerdateien"
124+
Filter="h;hpp;hxx;hm;inl;inc;xsd"
125+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
126+
<File
127+
RelativePath="..\..\MemoryModule.h">
128+
</File>
129+
</Filter>
130+
<Filter
131+
Name="Ressourcendateien"
132+
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
133+
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
134+
</Filter>
135+
</Files>
136+
<Globals>
137+
</Globals>
138+
</VisualStudioProject>

example/DllMemory.ncb

67 KB
Binary file not shown.

example/DllMemory.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Microsoft Visual Studio Solution File, Format Version 8.00
2+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleDLL", "SampleDLL\SampleDLL.vcproj", "{B293DAC4-5BCA-4413-9B7B-92CB56459875}"
3+
ProjectSection(ProjectDependencies) = postProject
4+
{D0226BB5-3A02-4C91-893A-F36567AED5C5} = {D0226BB5-3A02-4C91-893A-F36567AED5C5}
5+
EndProjectSection
6+
EndProject
7+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DllLoader", "DllLoader\DllLoader.vcproj", "{D0226BB5-3A02-4C91-893A-F36567AED5C5}"
8+
ProjectSection(ProjectDependencies) = postProject
9+
EndProjectSection
10+
EndProject
11+
Global
12+
GlobalSection(SolutionConfiguration) = preSolution
13+
Debug = Debug
14+
Release = Release
15+
EndGlobalSection
16+
GlobalSection(ProjectConfiguration) = postSolution
17+
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Debug.ActiveCfg = Debug|Win32
18+
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Debug.Build.0 = Debug|Win32
19+
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Release.ActiveCfg = Release|Win32
20+
{B293DAC4-5BCA-4413-9B7B-92CB56459875}.Release.Build.0 = Release|Win32
21+
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Debug.ActiveCfg = Debug|Win32
22+
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Debug.Build.0 = Debug|Win32
23+
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Release.ActiveCfg = Release|Win32
24+
{D0226BB5-3A02-4C91-893A-F36567AED5C5}.Release.Build.0 = Release|Win32
25+
EndGlobalSection
26+
GlobalSection(ExtensibilityGlobals) = postSolution
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityAddIns) = postSolution
29+
EndGlobalSection
30+
EndGlobal

example/DllMemory.suo

11 KB
Binary file not shown.

example/SampleDLL/SampleDLL.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "SampleDLL.h"
2+
3+
extern "C" {
4+
5+
SAMPLEDLL_API int addNumbers(int a, int b)
6+
{
7+
return a + b;
8+
}
9+
10+
}

example/SampleDLL/SampleDLL.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "C" {
2+
3+
#ifdef SAMPLEDLL_EXPORTS
4+
#define SAMPLEDLL_API __declspec(dllexport)
5+
#else
6+
#define SAMPLEDLL_API __declspec(dllimport)
7+
#endif
8+
9+
SAMPLEDLL_API int addNumbers(int a, int b);
10+
11+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy