ブラウザでダウンロード
Framework から Win32API を利用する為の dll 作成アプリケーションとして目的を達成すれば良いのであれば、無理に .NET から dll を直接呼び出そうとせずに、都合の良いインターフェイスにした dll で 橋渡しをすると良い場合もあります 01. // ********************************************************* 02. // dll 作成スケルトン 03. // ( VC++ 2005 より ) 04. // ********************************************************* 05. 06. #define _WIN32_WINNT 0x0500 07. #define WIN32_LEAN_AND_MEAN 08. #define WINDOWHOOK_API __declspec(dllexport) 09. 10. #include <windows.h> 11. #include <stdlib.h> 12. #include <malloc.h> 13. #include <memory.h> 14. #include <tchar.h> 15. #include <stdio.h> 16. 17. WINDOWHOOK_API int fnWindowHook( void ); 18. 19. 20. // ********************************************************* 21. // エントリポイント 22. // ********************************************************* 23. BOOL APIENTRY DllMain( 24. HMODULE hModule, 25. DWORD ul_reason_for_call, 26. LPVOID lpReserved 27. ) 28. { 29. switch (ul_reason_for_call) { 30. case DLL_PROCESS_ATTACH: 31. case DLL_THREAD_ATTACH: 32. case DLL_THREAD_DETACH: 33. case DLL_PROCESS_DETACH: 34. break ; 35. } 36. return TRUE; 37. } 38. 39. 40. // ********************************************************* 41. // エクスポートする関数 42. // HKEY_LOCAL_MACHINE のデータ取得 43. // 戻り値はデータのタイプ( -1 はエラー ) 44. // ********************************************************* 45. WINDOWHOOK_API DWORD RegReadLocalMachine( 46. LPTSTR key, LPTSTR entry, 47. LPTSTR value, DWORD size) 48. { 49. 50. LONG nRet; 51. HKEY hKey; 52. DWORD nType; 53. nType = -1; 54. 55. nRet = RegOpenKeyEx( 56. HKEY_LOCAL_MACHINE, 57. key, 58. 0, 59. KEY_ALL_ACCESS, 60. &hKey 61. ); 62. if ( nRet == ERROR_SUCCESS ) { 63. nRet = RegQueryValueEx( 64. hKey, 65. entry, 66. NULL, 67. &nType, 68. ( LPBYTE )value, 69. &size 70. ); 71. } 72. 73. RegCloseKey( hKey ); 74. 75. return nType; 76. } Win32.def
1. LIBRARY "Win32.dll" 2. 3. EXPORTS 4. RegReadLocalMachine @1 ![]() VB.NET からの呼び出しインターネットエクスプローラのバージョンを表示しています ![]() 01. Imports System.Text 02. Imports System.Runtime.InteropServices 03. 04. Module Module1 05. 06. <DllImport( "Win32.dll" , CharSet:=CharSet. Ansi )> _ 07. Public Function RegReadLocalMachine( _ 08. ByVal key As String , _ 09. ByVal entry As String , _ 10. ByVal value As StringBuilder, _ 11. ByVal size As Int32) As Int32 12. End Function 13. 14. Sub Main() 15. 16. Dim buffer As New StringBuilder(512) 17. Dim ret As Int32 18. 19. ret = RegReadLocalMachine( _ 20. "SOFTWARE\Microsoft\Internet Explorer" , _ 21. "Version" , _ 22. buffer, _ 23. 512) 24. 25. Console.WriteLine(buffer.ToString(), 512) 26. 27. End Sub 28. 29. End Module レジストリタイプ01. #define REG_NONE ( 0 ) // No value type 02. #define REG_SZ ( 1 ) // Unicode nul terminated string 03. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string 04. // (with environment variable references) 05. #define REG_BINARY ( 3 ) // Free form binary 06. #define REG_DWORD ( 4 ) // 32-bit number 07. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD) 08. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number 09. #define REG_LINK ( 6 ) // Symbolic Link (unicode) 10. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings 11. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map 12. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description 13. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 ) 14. #define REG_QWORD ( 11 ) // 64-bit number 15. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD) |