从外部DLL资源文件VB6读取文本文件内容

时间:2014-07-17 12:46:41

标签: dll resources external loadlibrary

我尝试从自定义DLL资源文件加载外部文本,但它无法正常工作。

资源文件内容(Test.dll,Test.rc和Test.res包含Eula.txt),Eula.txt文件大约是6Kb:

900 CUSTOM  "Eula.txt"

我正在使用这样的代码:

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long  
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long  
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Public Function LoadStrRes(lgResID As Long) As String  
 On Error Resume Next  

 Dim lgRet As Long  
 Dim stBuff As String * 32768  
 Dim lgBuffPos As Long  
 Dim stFile As String  

 stFile = App.Path & "\Test.dll"  

 lgRet = LoadLibrary(stFile)  

 Call LoadString(lgRet, lgResID, stBuff, Len(stBuff))  

 lgBuffPos = InStr(1, stBuff, Chr$(0))  

 LoadStrRes = Left$(stBuff, lgBuffPos - 1)  

 Call FreeLibrary(lgRet)  

 Exit Function  
End Function  

调用这样的函数:

Dim stTxtData As String  

stTxtData = LoadStrRes(900)  

txtEula.Text = stTxtData

有人可以告诉我为什么它不适合我?

此致

1 个答案:

答案 0 :(得分:1)

LoadStringdocumentation中描述为用于加载字符串资源(意为STRINGTABLE),而不是通用RC_DATA或CUSTOM资源。将你的字符串放在适当的STRINGTABLE中,并且它可以加载字符串,尽管由于大小而存储整个EULA可能会有问题。