#include <stdio.h> int main (void) { printf( "hello test with ddk\n"); return 0; }
TARGETNAME=test TARGETPATH=obj TARGETTYPE=PROGRAM SOURCES=test.c
#include <stdio.h> int __cdecl main (void) { printf( "hello test with ddk\n"); return 0; }
TARGETNAME=test TARGETPATH=obj TARGETTYPE=PROGRAM SOURCES=test.c UMTYPE=console UMBASE=0x00400000 UMENTRY=main
#include <stdio.h> int __cdecl main (void) { printf( "hello test with ddk\n"); return 0; } put the above lines in lets say test.c =========================================== TARGETNAME=test TARGETPATH=obj TARGETTYPE=PROGRAM SOURCES=test.c UMTYPE=console UMBASE=0x00400000 UMENTRY=main put this is sources file (no extension just plain sources should be the name and the entries after = are case sensitive MAIn , Main etc wont work just plain lower case main will work ================================================= copy paste one of the makefile (no extension just plain makefile is the name of the file) it will contain this # # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV)\makefile.def ============================================ open the cmd prompt and type build your hello world exe should be ready
TARGETNAME=test TARGETPATH=obj TARGETTYPE=PROGRAM SOURCES=test.c UMTYPE=windows UMBASE=0x00400000 UMENTRY=winmain
#include <windows.h> int APIENTRY WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MessageBox(NULL,"Hello DDK Gui","Neat Gui MsgBox",MB_OK); return 0; }
TARGETNAME=test TARGETPATH=obj TARGETTYPE=PROGRAM SOURCES=menu_one.c \ menu_one.rc UMTYPE=windows UMBASE=0x00400000 UMENTRY=winmain
#include "precomp.h" #pragma hdrstop //Globals HINSTANCE DLLModuleHandle; BOOL APIENTRY DllMain(HINSTANCE aHandle, DWORD aReason, LPVOID aReserved) { switch (aReason) { case DLL_PROCESS_ATTACH: DLLModuleHandle = aHandle; DisableThreadLibraryCalls(DLLModuleHandle); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } UINT AddTwoNum(UINT a,UINT b) { return a+b; } UINT SubTwoNum(UINT a,UINT b) { return a-b; } UINT MulTwoNum(UINT a,UINT b) { return a*b; }
LIBRARY TestDll EXPORTS AddTwoNum SubTwoNum MulTwoNum
#include <windows.h> #include <stdio.h> __declspec(dllexport) UINT AddTwoNum(UINT a,UINT b); __declspec(dllexport) UINT SubTwoNum(UINT a,UINT b); __declspec(dllexport) UINT MulTwoNum(UINT a,UINT b);
#include "TestDll.h"
TARGETNAME=TestDll TARGETTYPE=DYNLINK DLLENTRY=_DllMainCRTStartup USE_MSVCRT=1 SAMPLE_COMMON_DIR=D:\DDKTests TARGETPATH=$(SAMPLE_COMMON_DIR) SOURCES= TestDll.c TARGETLIBS= \ $(SDK_LIB_PATH)\user32.lib \ $(SDK_LIB_PATH)\kernel32.lib \ UMTYPE=windows PRECOMPILED_INCLUDE=precomp.h PRECOMPILED_PCH=precomp.pch PRECOMPILED_OBJ=precomp.obj
D:\DDKTests\TestDll>dir /b Testdll.h makefile precomp.h sources TestDll.c TestDll.def D:\DDKTests\TestDll> now lets create a Test app code for testapp.c [code] #include "precomp.h" #pragma hdrstop int __cdecl main (void) { int result,a,b; a = 10; b = 5; printf("\nCompiling UserModeDll with DDk\n\nAnd Calling Functions From Dll\n\n"); printf("Following three calls are done from TestDll\n\n"); result = AddTwoNum(a,b); printf("Addition of Two numbers %d, %d = %d\n",a,b,result); result = SubTwoNum(a,b); printf("Subtraction of Two numbers %d, %d = %d\n",a,b,result); result = MulTwoNum(a,b); printf("Multiplication of Two numbers %d, %d = %d\n",a,b,result); printf("done\n"); return 0; }
TARGETNAME=TestApp TARGETTYPE=PROGRAM SAMPLE_COMMON_DIR=D:\DDKTests TARGETPATH=$(SAMPLE_COMMON_DIR) UMENTRY=main SOURCES=TestApp.c TARGETLIBS=D:\DDKTests\i386\TestDll.lib UMTYPE=console PRECOMPILED_INCLUDE=precomp.h PRECOMPILED_PCH=precomp.pch PRECOMPILED_OBJ=precomp.obj
D:\DDKTests\TestApp>dir /b makefile sources TestApp.c precomp.h Testdll.h D:\DDKTests\TestApp>
DIRS= \ TestDll \ TestApp \
D:\DDKTests>tree /f Folder PATH listing D:. �� dirs �� ��������TestApp �� makefile �� sources �� TestApp.c �� precomp.h �� Testdll.h �� ��������TestDll Testdll.h makefile precomp.h sources TestDll.c TestDll.def D:\DDKTests>
D:\DDKTests>build BUILD: Adding /Y to COPYCMD so xcopy ops won't hang. BUILD: Object root set to: ==> objfre_w2K_x86 BUILD: Compile and Link for i386 BUILD: Loading D:\WINDDK\3790~1.183\build.dat... BUILD: Computing Include file dependencies: BUILD: Examining d:\ddktests directory tree for files to d:\ddktests\testdll - 2 source files (39 lines) d:\ddktests\testapp - 2 source files (27 lines) Total of 4 source files (66 lines) to compile in 2 direct BUILD: Compiling (NoSync) d:\ddktests\testdll directory Precompiling - precomp.h for i386 Compiling - testdll.c for i386 Building Library - .lib for i386 BUILD: Compiling (NoSync) d:\ddktests\testapp directory Precompiling - precomp.h for i386 Compiling - testapp.c for i386 BUILD: Linking d:\ddktests\testdll directory Linking Executable - testdll\i386\testdll.dll for i386 BUILD: Linking d:\ddktests\testapp directory Linking Executable - testapp\i386\testapp.exe for i386 BUILD: Done 6 files compiled - 13 LPS 1 library built 2 executables built D:\DDKTests> [code] lets check the tree what it built [code] D:\DDKTests>tree /f Folder PATH listing Volume serial number is 71FAE346 191A:1EDE D:. �� dirs �� buildfre_w2K_x86.log �� ��������TestApp �� �� makefile �� �� sources �� �� TestApp.c �� �� precomp.h �� �� Testdll.h �� �� �� ��������objfre_w2K_x86 �� �� _objects.mac �� �� �� ��������i386 �� precomp.pch �� precomp.obj �� testapp.obj �� ��������TestDll �� �� Testdll.h �� �� makefile �� �� precomp.h �� �� sources �� �� TestDll.c �� �� TestDll.def �� �� �� ��������objfre_w2K_x86 �� �� _objects.mac �� �� �� ��������i386 �� precomp.pch �� precomp.obj �� testdll.obj �� ��������i386 TestDll.lib TestDll.exp TestDll.dll TestDll.pdb TestApp.exe TestApp.pdb D:\DDKTests> [code] lets try running the app and see if it really works ? [code] D:\DDKTests\i386>TestApp.exe Compiling UserModeDll with DDk And Calling Functions From Dll Following three calls are done from TestDll Addition of Two numbers 10, 5 = 15 Subtraction of Two numbers 10, 5 = 5 Multiplication of Two numbers 10, 5 = 50 done D:\DDKTests\i386>
01001D15 >MOV EDI,EDI 01001D17 PUSH ESI 01001D18 PUSH EDI ; /format 01001D19 PUSH TestApp.??_C@_0EC@LBDINKF@?6Compili>; |/format = " Compiling UserModeDll with DDk And Calling Functions From Dll" 01001D1E CALL TestApp.printf ; |\printf 01001D23 MOV DWORD PTR SS:[ESP],TestApp.??_C@_0CO>; |ASCII "Following three calls are done from TestDll " 01001D2A CALL TestApp.printf ; \printf 01001D2F POP ECX 01001D30 PUSH 5 01001D32 POP EDI 01001D33 PUSH EDI 01001D34 PUSH 0A 01001D36 POP ESI 01001D37 PUSH ESI 01001D38 CALL TestApp._AddTwoNum@8;JMP to TestDll.AddTwoNum 01001D3D PUSH EAX ; /<%d> 01001D3E PUSH EDI ; |<%d> 01001D3F PUSH ESI ; |<%d> 01001D40 PUSH TestApp.??_C@_0CL@HHFCGPC@Addition?>; |format = "Addition of Two numbers %d, %d = %d " 01001D45 CALL TestApp.printf ; \printf 010011F8=TestApp.??_C@_0EC@LBDINKF@?6Compiling?5UserModeDll?5with?5DDk?6@ (ASCII 0A,"Compiling ") testapp.c:12. printf("\nCompiling UserModeDll with DDk\n\nAnd Calling Functions From Dll\n\n"); looks like name mangling has been done i tried extern "C" before __declspec but i find ddk is complaining have to find out how to remove this mangling crap following the dll function testdll.c:28. return a+b; 46A010AD >MOV EDI,EDI ; { 46A010AF PUSH EBP ; { 46A010B0 MOV EBP,ESP 46A010B2 MOV EAX,DWORD PTR SS:[EBP+C] ; return a+b; 46A010B5 MOV ECX,DWORD PTR SS:[EBP+8] 46A010B8 ADD EAX,ECX 46A010BA POP EBP ; } 46A010BB RETN 8
There are 31,322 total registered users.
[+] expand