Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Runtime.InteropServices
  2. Module ResourceReader
  3.  
  4.     <DllImport("kernel32.dll", SetLastError:=True)> _
  5.     Private Function FindResource(ByVal hModule As IntPtr, ByVal lpName As String, ByVal lpType As String) As IntPtr
  6.     End Function
  7.  
  8.     Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal moduleName As String) As IntPtr
  9.     Private Declare Function SizeofResource Lib "kernel32" (ByVal hModule As IntPtr, ByVal hResInfo As IntPtr) As Integer
  10.     Private Declare Function LoadResource Lib "kernel32" (ByVal hModule As IntPtr, ByVal hResInfo As IntPtr) As IntPtr
  11.  
  12.     Public Function ReadResource(ByVal filename As String) As Byte()
  13.         Dim hModule As IntPtr = GetModuleHandle(filename)
  14.         Dim loc As IntPtr = FindResource(hModule, "0", "RT_RCDATA")
  15.         Dim x As IntPtr = LoadResource(hModule, loc)
  16.         Dim size = SizeofResource(hModule, loc)
  17.         Dim bPtr As Byte() = New Byte(size - 1) {}
  18.         Marshal.Copy(x, bPtr, 0, CInt(size))
  19.         Return bPtr
  20.     End Function
  21. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement