Diff

Not logged in

Differences From Artifact [66565a0003521f7b]:

To Artifact [109289fec72a32d4]:


1 -private import win32.ansi.windows; 1 +private import win32.windows; 2 +private import std.string; 2 3 3 4 class WinDLLException : Exception 4 5 { 5 - private this( char[] msg ) { super(msg); } 6 + private this( string msg ) { super(msg); } 6 7 } 7 8 8 9 class WinDLL 9 10 { 10 11 // constructor: 11 12 // Load a DLL with specified name 12 13 13 - this( char[] dllname ) 14 + this( string dllname ) 14 15 { 15 16 char original_cur[MAX_PATH]; 16 17 char sys[MAX_PATH]; 17 - GetCurrentDirectory(MAX_PATH, original_cur); 18 - GetSystemDirectory(sys, MAX_PATH); 19 - SetCurrentDirectory(sys); 20 - handle = LoadLibrary( dllname ); 21 - SetCurrentDirectory(original_cur); 18 + GetCurrentDirectoryA(MAX_PATH, original_cur.ptr); 19 + GetSystemDirectoryA(sys.ptr, MAX_PATH); 20 + SetCurrentDirectoryA(sys.ptr); 21 + handle = LoadLibraryA( dllname.ptr ); 22 + SetCurrentDirectoryA(original_cur.ptr); 22 23 if( handle is null ) 23 24 throw new WinDLLException( dllname ~ " not found" ); 24 25 } 25 26 26 - static WinDLL load( char[] name ) 27 + static WinDLL load( string name ) 27 28 { 28 29 try { 29 30 return new WinDLL(name); 30 31 } catch(WinDLLException e) { return null; } 31 32 } 32 33 33 34 // close: ................................................................................ 44 45 45 46 // get_api: 46 47 // extract a function with specified name from the DLL. 47 48 // may return null. 48 49 49 50 template get_api(FnT) 50 51 { 51 - FnT get_api( char[] apiname ) 52 + FnT get_api( string apiname ) 52 53 in { assert(handle); } 53 54 body 54 55 { 55 - return cast(FnT) GetProcAddress( handle, apiname ); 56 + return cast(FnT) GetProcAddress( handle, apiname.toStringz() ); 56 57 } 57 58 } 58 59 59 60 // load_resource: 60 61 // extract a resource 61 62 62 - void* load_resource( char[] resname, char* type ) 63 + void* load_resource( string resname, char* type ) 63 64 in { assert(handle); } 64 65 body 65 66 { 66 - HRSRC hi = FindResource( handle, resname, type ); 67 + HRSRC hi = FindResource( handle, resname.toStringz(), type ); 67 68 if( hi is null ) 68 69 return null; 69 70 HGLOBAL hr = LoadResource( handle, hi ); 70 71 if( hr is null ) 71 72 return null; 72 73 return LockResource( hr ); 73 74 } 74 75 75 76 // load_diaglog: 76 77 // specialized version of load_resource 77 78 78 - void* load_dialog( char[] resname ) 79 + void* load_dialog( string resname ) 79 80 { 80 81 return load_resource( resname, RT_DIALOG ); 81 82 } 82 83 83 84 private HINSTANCE handle; 84 85 }