请帮助查看样本 [英] Please help to view the sample

查看:69
本文介绍了请帮助查看样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想从DLL文件中获取字符串资源,该代码适用于

Vista x86,但它不适用于Vista x64,为什么?任何人都可以帮助查看

下面的代码?非常感谢你。


///////////////////////////////// /////////////////////////////////////////////////


公共类GetResourceStringFromFile


私有声明函数LoadLibrary Lib" kernel32"别名

" LoadLibraryA" (ByVal lpLibFileName As String)作为整数

私有声明函数LoadString Lib" user32"别名LoadStringA

(ByVal hInstance As Integer,ByVal uID As Integer,ByVal lpBuffer As String,

ByVal nBufferMax As Integer)As Integer

私有声明函数FreeLibrary Lib" kernel32" (ByVal

hLibModule As Integer)as Integer


公共共享函数GetResourceStringFromFile(ByVal sModule As

String,ByVal idString As Integer )作为字符串

Dim hModule作为整数

Dim nChars作为整数

Dim Buffer As New

Microsoft.VisualBasic .Compatibility.VB6.FixedLengt hString(260)

Dim ReturnValue As String =""


尝试

hModule = LoadLibrary(sModule)

如果是hModule那么

nChars = LoadString(hModule,idString,Buffer.Value,

260)

如果nChars 0那么

ReturnValue =

Microsoft.VisualBasic.Left(Buffer.Value,nChars)

结束如果


FreeLibrary(hModule)

结束如果

Catch ex As Exception

结束尝试

返回"

结束功能


结束班

解决方案

" YXQ" < ga *** @ 163.netschrieb


你好,

我想从DLL文件中获取字符串资源,代码工作正常很好
Vista x86的b $ b,但它不适用于Vista x64,为什么?任何人都可以帮助查看下面的代码吗?非常感谢你。


///////////////////////////////// /////////////////////////////////////////////////


公共类GetResourceStringFromFile


私有声明函数LoadLibrary Lib" kernel32"别名

" LoadLibraryA" (ByVal lpLibFileName As String)作为整数

私有声明函数LoadString Lib" user32" Alias

" LoadStringA" (ByVal hInstance As Integer,ByVal uID as Integer,

ByVal lpBuffer As String,ByVal nBufferMax As Integer)As Integer

Private Declare Function FreeLibrary Lib" kernel32" (ByVal

hLibModule As Integer)As Integer



句柄必须声明为IntPtr。 IntPtr是特定于平台的,并且自动确定大小正确的大小,即。 32或64位,具体取决于平台。

而Integer = Int32。


观看声明:


HMODULE LoadLibrary(

LPCTSTR lpFileName

);

int LoadString(HINSTANCE hInstance,

UINT uID,

LPTSTR lpBuffer,

int nBufferMax

);


BOOL FreeLibrary(

HMODULE hModule

);


类型翻译:


int -IntPtr

UINT = unsigned int -IntPtr

HMODULE = HINSTANCE = HANDLE = PVOID = void * -IntPtr

BOOL = int -IntPtr

示例:


私有声明函数LoadLibrary Lib" kernel32"别名

" LoadLibraryA" (ByVal lpLibFileName As String)作为IntPtr


参见:
http://msdn2.microsoft.com/en-us/library/ms241064.aspx
http://msdn2.microsoft.com/en-us/library/8ck8e1y2.aspx

社区:如何作为布尔是什么?如何治疗?难道不是IntPtr吗?我已经将BO $转换为布尔,但这似乎是错误的。


Armin


" YXQ" < ga *** @ 163.netschrieb


Haven不会看其余的代码...


此外,如果从非托管[API]

函数中获取字符串,请使用Stringbuilder。注意,字符串是不可变的。在.Net。无论如何都不需要使用

VB6.FixedLengthString。

参见 http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx

特别是 http://msdn2.microsoft.com/en-us/library/s9ts558h.aspx (头条

固定长度字符串缓冲区)。

(但不要依赖那里的声明......)

因此,在LoadString中,声明ByVal lpBuffer As StringBuilder。在调用

函数之前,请填充stringbuilder。


还可以根据您的类型在函数中交换变量类型

在声明中使用。

Armin


" yxq" < ga *** @ 163.netschrieb:


我想从DLL文件中获取字符串资源,该代码适用于

Vista x86,但它不适用于Vista x64,为什么?任何人都可以帮助查看

下面的代码?非常感谢你。



你的函数声明是错误的。我建议查看样本

< URL:http://dotnet.mvps.org/temp/Win32Res.zip>。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL :http://dotnet.mvps.org/dotnet/faqs/>


Hello,
I want to get the string resource from DLL file, the code work well for
Vista x86, but it will not work on Vista x64, why? can anyone help to view
the code below? thank you very much.

//////////////////////////////////////////////////////////////////////////////////

Public Class GetResourceStringFromFile

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

Public Shared Function GetResourceStringFromFile(ByVal sModule As
String, ByVal idString As Integer) As String
Dim hModule As Integer
Dim nChars As Integer
Dim Buffer As New
Microsoft.VisualBasic.Compatibility.VB6.FixedLengt hString(260)
Dim ReturnValue As String = ""

Try
hModule = LoadLibrary(sModule)
If hModule Then
nChars = LoadString(hModule, idString, Buffer.Value,
260)
If nChars 0 Then
ReturnValue =
Microsoft.VisualBasic.Left(Buffer.Value, nChars)
End If

FreeLibrary(hModule)
End If
Catch ex As Exception
End Try
Return ""
End Function

End Class

解决方案

"yxq" <ga***@163.netschrieb

Hello,
I want to get the string resource from DLL file, the code work well
for Vista x86, but it will not work on Vista x64, why? can anyone
help to view the code below? thank you very much.

//////////////////////////////////////////////////////////////////////////////////

Public Class GetResourceStringFromFile

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


Handles must be declared as IntPtr. IntPtr is plattform specific and
automatically the correct size, ie. 32 or 64 bit depending on the plattform.
Whereas Integer = Int32.

Watch the declarations:

HMODULE LoadLibrary(
LPCTSTR lpFileName
);
int LoadString( HINSTANCE hInstance,
UINT uID,
LPTSTR lpBuffer,
int nBufferMax
);

BOOL FreeLibrary(
HMODULE hModule
);

Type translation:

int -IntPtr
UINT = unsigned int -IntPtr
HMODULE = HINSTANCE = HANDLE = PVOID = void* -IntPtr
BOOL = int -IntPtr
Example:

Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibraryA" (ByVal lpLibFileName As String) As IntPtr

See also:
http://msdn2.microsoft.com/en-us/library/ms241064.aspx
http://msdn2.microsoft.com/en-us/library/8ck8e1y2.aspx
To the community: How is "As Boolean" treated? Shouldn''t it be IntPtr? I''ve
always translated BOOL to Boolean, but this seems to be wrong.

Armin


"yxq" <ga***@163.netschrieb

Haven''t looked at the rest of the code...

Also, use a Stringbuilder if you get a string back from an unmanaged [API]
function. Note that Strings are "immutable" in .Net. No need to use
VB6.FixedLengthString anyways.
See http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx,
especially http://msdn2.microsoft.com/en-us/library/s9ts558h.aspx (head line
"Fixed-Length String Buffers").
(but don''t rely on the declarations there...)
So, in LoadString, declare "ByVal lpBuffer As StringBuilder". Before calling
the function, fill the stringbuilder.

Also exchange the variable types in the function according to the types you
used in the Declares.
Armin


"yxq" <ga***@163.netschrieb:

I want to get the string resource from DLL file, the code work well for
Vista x86, but it will not work on Vista x64, why? can anyone help to view
the code below? thank you very much.

Your function declarations are wrong. I suggest to check out the sample
<URL:http://dotnet.mvps.org/temp/Win32Res.zip>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于请帮助查看样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆