ブラウザでダウンロード Framework から Win32API を利用する為の dll 作成アプリケーションとして目的を達成すれば良いのであれば、無理に .NET から dll を直接呼び出そうとせずに、都合の良いインターフェイスにした dll で 橋渡しをすると良い場合もあります
// *********************************************************
// dll 作成スケルトン
// ( VC++ 2005 より )
// *********************************************************
#define _WIN32_WINNT 0x0500
#define WIN32_LEAN_AND_MEAN
#define WINDOWHOOK_API __declspec(dllexport)
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
WINDOWHOOK_API int fnWindowHook(void);
// *********************************************************
// エントリポイント
// *********************************************************
BOOL APIENTRY DllMain(
HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// *********************************************************
// エクスポートする関数
// HKEY_LOCAL_MACHINE のデータ取得
// 戻り値はデータのタイプ( -1 はエラー )
// *********************************************************
WINDOWHOOK_API DWORD RegReadLocalMachine(
LPTSTR key, LPTSTR entry,
LPTSTR value, DWORD size)
{
LONG nRet;
HKEY hKey;
DWORD nType;
nType = -1;
nRet = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
key,
0,
KEY_ALL_ACCESS,
&hKey
);
if ( nRet == ERROR_SUCCESS ) {
nRet = RegQueryValueEx(
hKey,
entry,
NULL,
&nType,
(LPBYTE)value,
&size
);
}
RegCloseKey( hKey );
return nType;
}
Win32.def
LIBRARY "Win32.dll" EXPORTS RegReadLocalMachine @1
VB.NET からの呼び出しインターネットエクスプローラのバージョンを表示しています
Imports System.Text
Imports System.Runtime.InteropServices
Module Module1
<DllImport("Win32.dll", CharSet:=CharSet.Ansi)> _
Public Function RegReadLocalMachine( _
ByVal key As String, _
ByVal entry As String, _
ByVal value As StringBuilder, _
ByVal size As Int32) As Int32
End Function
Sub Main()
Dim buffer As New StringBuilder(512)
Dim ret As Int32
ret = RegReadLocalMachine( _
"SOFTWARE\Microsoft\Internet Explorer", _
"Version", _
buffer, _
512)
Console.WriteLine(buffer.ToString(), 512)
End Sub
End Module
レジストリタイプ
#define REG_NONE ( 0 ) // No value type
#define REG_SZ ( 1 ) // Unicode nul terminated string
#define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
// (with environment variable references)
#define REG_BINARY ( 3 ) // Free form binary
#define REG_DWORD ( 4 ) // 32-bit number
#define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
#define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
#define REG_LINK ( 6 ) // Symbolic Link (unicode)
#define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
#define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
#define REG_QWORD ( 11 ) // 64-bit number
#define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
|
|