Click here to Skip to main content
11,428,332 members (66,023 online)
Click here to Skip to main content
Articles » Languages » C# » PInvoke » Downloads
Add your own
alternative version

Late binding on native DLLs with C#

, 12 Nov 2001 BSD
Delaying which DLL export to call until runtime is not possible with C#. This article shows you how to make it possible.
dyninvok_src.zip
article_src
makefile
; -------------------------------------------------------------
;
; InvokeFuncAsm - Invokes a function through a function pointer passed as
; the first argument. All other parameters are forwarded on, plus the return
; value of the function invoked is returned.
;
; Copyright (c) Richard Birkby, ThunderMain ltd, November 2001
;
; -------------------------------------------------------------

.386
.model flat

option prologue:none
option epilogue:none
option dotname


.code
align DWORD
DllMain     proc    stdcall public, instance:DWORD, reason:DWORD, reserved:DWORD
        mov     eax, 1  ; success
        ret	12
DllMain     endp


align DWORD
InvokeFunc	proc	stdcall	public, funcptr:DWORD

	pop	ecx	; save return address
	pop	edx	; Get function pointer
	push	ecx	; Restore return address
	jmp	edx	; Transfer control to the function pointer
InvokeFunc	endp

end

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 The BSD License

Share

About the Author

Richard Birkby
Web Developer
United Kingdom United Kingdom
Richard Birkby is a software engineer from London, UK, specializing in .Net. Richard has coded for many different sized companies from small venture-capital funded start-ups, to multi-national corporations (ie Microsoft). When he's not programming, he enjoys driving his sports car or eating curry (although never at the same time!).

Richard helps run CurryPages.com and has several other covert ventures in development. Stay tuned!

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150428.2 | Last Updated 13 Nov 2001
Article Copyright 2001 by Richard Birkby
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid