vb调用资源dll中自定义资源
我用vc++建立了一个简单动态链接库工程,然后加入了一个资源1.MP3,没有输出函数,请问在vb中应该怎么调用这个资源?比如存入内存直接运用。有高手能知道这样的资源DLL...
我用vc++ 建立了一个简单动态链接库工程,然后加入了一个资源1.MP3,没有输出函数,请问在vb中应该怎么调用这个资源?比如存入内存直接运用。有高手能知道这样的资源DLL创建方法也可以。本人小白,请经清楚哦。
展开
1个回答
展开全部
Option Explicit
Private Declare Function LoadLibraryEx Lib "kernel32" Alias "LoadLibraryExA" (ByVal lpLibFileName As String, ByVal hFile As Long, ByVal dwFlags As Long) As Long
Private Declare Function FindResource Lib "kernel32" Alias "FindResourceA" (ByVal hInstance As Long, ByVal lpName As String, ByVal lpType As String) As Long
Private Declare Function LoadResource Lib "kernel32" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function FreeResource Lib "kernel32" (ByVal hResData As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private module As Long
Private Sub Form_Load()
module = LoadLibraryEx("1.dll", 0, 2) 'LOAD_LIBRARY_AS_DATAFILE
If module <> 0 Then
Dim resource As Long
resource = FindResource(module, "资源名称", "资源类型")
If resource <> 0 Then
Dim mem As Long, result
mem = LoadResource(module, resource)
result = GlobalLock(mem) '这就是资源内的数据了。
GlobalFree mem
FreeResource mem
End If
End If
End Sub
追问
得到内存地址之后要怎么运用呢,比如写入文件,或者在内存播放这个MP3?
追答
Private module As Long
Private Sub Form_Load()
module = LoadLibraryEx("DLL名称.dll", 0, 2) 'LOAD_LIBRARY_AS_DATAFILE
If module <> 0 Then
Dim resource As Long
resource = FindResource(module, "资源名称", "资源类型")
If resource <> 0 Then
Dim memory As Long, hGlobal As Long, length As Long, file As Long
length = SizeofResource(module, resource)
hGlobal = LoadResource(module, resource)
file = CreateFile("文件名.mp3", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0)
If file <> INVALID_HANDLE_VALUE Then
WriteFile file, LockResource(hGlobal), length, length, 0
CloseHandle file
End If
FreeResource hGlobal
End If
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询