Click here to Skip to main content
12,747,366 members (37,063 online)
Click here to Skip to main content

Tagged as

Stats

12.6K views
266 downloads
6 bookmarked
Posted 24 Oct 2011

Dynamic Libraries with Delayed Function Loading

, 27 Oct 2011 Public Domain
This article explains how to create a dynamic library that loads exported functions the first time they are used, opposed to loading them when the library is loaded.
#pragma once

#define SAVE_RTN_ADDRESS \
	__asm push eax \
	__asm mov eax, [esp+4] \
	__asm mov rtn_addr, eax \
	__asm pop eax

#define SAVE_REGISTERS \
	__asm mov eax_save, eax \
	__asm mov ebx_save, ebx \
	__asm mov ecx_save, ecx \
	__asm mov edx_save, edx \
	__asm mov esi_save, esi \
	__asm mov edi_save, edi \
	__asm mov esp_save, esp \
	__asm mov ebp_save, ebp

#define LOAD_RTN_ADDRESS \
	__asm push eax \
	__asm mov eax, rtn_addr\
	__asm mov [esp+4], eax \
	__asm pop eax

#define LOAD_REGISTERS \
	__asm mov eax, eax_save \
	__asm mov ebx, ebx_save \
	__asm mov ecx, ecx_save \
	__asm mov edx, edx_save \
	__asm mov esi, esi_save \
	__asm mov edi, edi_save \
	__asm mov esp, esp_save \
	__asm mov ebp, ebp_save


#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#define PROC_IMPLEMENTATION(proc_name) \
	const char proc_##proc_name[] = TOSTRING(proc_name); \
	\
	__declspec(naked) \
	void proc_name() \
	{ \
		called_proc = proc_##proc_name; \
		__asm jmp proxy_proc \
	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

Vasil Bachvarov
Founder
Germany Germany
Software developer since April 2000.
Active in various areas, most notably C/C++ development with Windows platform, web development, scripting.
Coder by heart.
Interested in higher level software development techniques, abstractions, modeling, software factories.
Nuts and bolts guy.

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170215.1 | Last Updated 27 Oct 2011
Article Copyright 2011 by Vasil Bachvarov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid