473,609 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help to view the sample

yxq
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 GetResourceStri ngFromFile

Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As Integer
Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(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 GetResourceStri ngFromFile(ByVa l sModule As
String, ByVal idString As Integer) As String
Dim hModule As Integer
Dim nChars As Integer
Dim Buffer As New
Microsoft.Visua lBasic.Compatib ility.VB6.Fixed LengthString(26 0)
Dim ReturnValue As String = ""

Try
hModule = LoadLibrary(sMo dule)
If hModule Then
nChars = LoadString(hMod ule, idString, Buffer.Value,
260)
If nChars 0 Then
ReturnValue =
Microsoft.Visua lBasic.Left(Buf fer.Value, nChars)
End If

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

End Class
Feb 9 '07 #1
19 1905
"yxq" <ga***@163.nets chrieb
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 GetResourceStri ngFromFile

Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As Integer
Private Declare Function LoadString Lib "user32" Alias
"LoadString A" (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
"LoadLibrar yA" (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

Feb 9 '07 #2
"yxq" <ga***@163.nets chrieb

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.FixedLength String 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

Feb 9 '07 #3
"yxq" <ga***@163.nets chrieb:
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/>

Feb 9 '07 #4
yxq
Thank you for your help, but i have changed to the code below, it works well
on x86, but will not work on x64(only get a few dll's string), thank you.

/////////////////////////////////////////////////////////////////////////////////
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibrar yA"
(ByVal lpLibFileName As String) As Integer
Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(ByVal hInstance As IntPtr, 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 Function GetResourceStri ngFromFile(ByVa l sModule As String, ByVal
idString As Integer) As String

Dim Buffer As String = Space(&H1000)
Dim hModule As Integer

Try
hModule = LoadLibrary(sMo dule)
If hModule Then
Dim n As Int32 = LoadString(hMod ule, idString, Buffer,
Buffer.Length)
If n 0 Then
Return Left(Buffer, n)
End If
End If
Catch ex As Exception
End Try
Return ""
End Function

"yxq" <ga***@163.netÐ ´ÈëÏûÏ¢ÐÂÎÅ:OL* *************** @TK2MSFTNGP05.p hx.gbl...
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 GetResourceStri ngFromFile

Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As Integer
Private Declare Function LoadString Lib "user32" Alias
"LoadString A" (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 GetResourceStri ngFromFile(ByVa l sModule As
String, ByVal idString As Integer) As String
Dim hModule As Integer
Dim nChars As Integer
Dim Buffer As New
Microsoft.Visua lBasic.Compatib ility.VB6.Fixed LengthString(26 0)
Dim ReturnValue As String = ""

Try
hModule = LoadLibrary(sMo dule)
If hModule Then
nChars = LoadString(hMod ule, idString, Buffer.Value,
260)
If nChars 0 Then
ReturnValue =
Microsoft.Visua lBasic.Left(Buf fer.Value, nChars)
End If

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

End Class


Feb 10 '07 #5
"yxq" <ga***@163.nets chrieb
Thank you for your help, but i have changed to the code below, it works
well on x86, but will not work on x64(only get a few dll's string), thank
you.

/////////////////////////////////////////////////////////////////////////////////
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibrar yA"
(ByVal lpLibFileName As String) As Integer
Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(ByVal hInstance As IntPtr, 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

You should change not only some types. Correct them all. For example, the
return value of LoadLibrary must be Intptr. As I wrote, handles must be
Intptr.

I was wrong with the type translation table. Correction:

int -Integer/Int32
UINT = unsigned int -VB 2005: UInteger/UInt32, VB 2003: Integer/Int32
HMODULE = HINSTANCE = HANDLE = PVOID = void* -IntPtr
BOOL -Boolean
->

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

Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(ByVal hInstance As IntPtr, ByVal uID As UInteger, ByVal lpBuffer As
StringBuilder, ByVal nBufferMax As Integer) As Integer

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule
As IntPtr) As Boolean
Armin

Feb 10 '07 #6
"Armin Zingler" <az*******@free net.deschrieb:
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibrar yA"
(ByVal lpLibFileName As String) As IntPtr

Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(ByVal hInstance As IntPtr, ByVal uID As UInteger, ByVal lpBuffer As
StringBuilder, ByVal nBufferMax As Integer) As Integer

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule
As IntPtr) As Boolean
.... and you can even get rid of the alias and declare the function as 'Auto'
('Declare Auto Function...').

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

Feb 10 '07 #7
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschri eb
"Armin Zingler" <az*******@free net.deschrieb:
Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As IntPtr

Private Declare Function LoadString Lib "user32" Alias
"LoadString A" (ByVal hInstance As IntPtr, ByVal uID As UInteger,
ByVal lpBuffer As StringBuilder, ByVal nBufferMax As Integer) As
Integer

Private Declare Function FreeLibrary Lib "kernel32" (ByVal
hLibModule As IntPtr) As Boolean

... and you can even get rid of the alias and declare the function
as 'Auto' ('Declare Auto Function...').

I didn't look at it at all. Had to find out whether "int" is Intptr or
Int32. :-)
Armin

Feb 10 '07 #8
yxq
Thank you, but i tried all your suggestions, but did not work yet.
If add the "Auto" to the API, it will not work on x64(include x86).
Modifid the Integer to Intptr, not effect.

Could you please help me to test on OS-64bit? i want to get the string in
Shell32.dll(Res ID is -22985), it can return "Folder Options".
I used the code below. It work well on x86, but will not work on x64.

//////////////////////////////////////////////////////////////////////////
MessageBox.Show (GetResourceStr ingFromFile("C: \Windows\System 32\shell32.dll" ,
22985))

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibrar yA"
(ByVal lpLibFileName As String) As IntPtr
Private Declare Function LoadString Lib "user32" Alias "LoadString A"
(ByVal hInstance As IntPtr, ByVal uID As UInteger, ByVal lpBuffer As String,
ByVal nBufferMax As Integer) As Integer
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As
IntPtr) As Integer

Public Function GetResourceStri ngFromFile(ByVa l sModule As String, ByVal
idString As Integer) As String

Dim Buffer As String = Space(&H1000)
Dim hModule As Integer

Try
hModule = LoadLibrary(sMo dule)
If hModule Then
Dim n As Int32 = LoadString(hMod ule, idString, Buffer,
Buffer.Length)
If n 0 Then
Return Left(Buffer, n)
End If
End If
Catch ex As Exception
End Try
Return ""
End Function

"Armin Zingler" <az*******@free net.de>
??????:uw****** ********@TK2MSF TNGP03.phx.gbl. ..
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschri eb
>"Armin Zingler" <az*******@free net.deschrieb:
Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As IntPtr

Private Declare Function LoadString Lib "user32" Alias
"LoadString A" (ByVal hInstance As IntPtr, ByVal uID As UInteger,
ByVal lpBuffer As StringBuilder, ByVal nBufferMax As Integer) As
Integer

Private Declare Function FreeLibrary Lib "kernel32" (ByVal
hLibModule As IntPtr) As Boolean

... and you can even get rid of the alias and declare the function
as 'Auto' ('Declare Auto Function...').


I didn't look at it at all. Had to find out whether "int" is Intptr or
Int32. :-)
Armin

Feb 11 '07 #9
"yxq" <ga***@163.nets chrieb
Thank you, but i tried all your suggestions, but did not work yet.
If add the "Auto" to the API, it will not work on x64(include x86).
Modifid the Integer to Intptr, not effect.

Could you please help me to test on OS-64bit?
If you send me one?
i want to get the
string in Shell32.dll(Res ID is -22985), it can return "Folder
Options".
I used the code below. It work well on x86, but will not work on
x64.

//////////////////////////////////////////////////////////////////////////
MessageBox.Show (GetResourceStr ingFromFile("C: \Windows\System 32\shell32.dll" ,
22985))

Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibrar yA" (ByVal lpLibFileName As String) As IntPtr
Private Declare Function LoadString Lib "user32" Alias
"LoadString A" (ByVal hInstance As IntPtr, ByVal uID As UInteger,
ByVal lpBuffer As String, ByVal nBufferMax As Integer) As Integer

Still wrong declaration. Use a Stringbuilder for lpBuffer. See this thread
for explanation.
Armin

Feb 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
1839
by: Raymond Hettinger | last post by:
Based on the feedback here on comp.lang.python, the pep has been updated: www.python.org/peps/pep-0322.html The key changes are: * reversed() is being preferred to ireverse() as the best name.
28
3290
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my neighborhood. I'm really picky about that... I have 12 chairs besides my own, and I want them all...
0
3323
by: thefirstwml | last post by:
Hi, I cannot view CLOB fields when I use the Sample Contents in the Control Center. When I insert values, I see the CLOB fields as blank. A fellow developer is using the exact same DB2 UDB version on the desktop, connecting to the DB2 UDB 8.1 on AIX, and he can see the sample contents just fine. When I use Java to query the data, the data prints out just fine (using a Clob data type and BufferedReader). What settings do I need to...
23
3258
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
4
1167
by: J | last post by:
I am a newbie in vb.net and gdi+, in my windows app, I using System.drawing to display image file, now when user view a multipage tiff file, they moved to 3rd page, then chose a new tiff file, it's display 3rd page instead of first page, I tried something but not works, so what I need to do? please help. Thank in advance.
1
9622
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
7
1487
by: Mickyd1561 | last post by:
Hey everyone I'm new to this groups thing and thought maybe someone can help me. My problem is that I can't view specific images on only one website. www.baseballu.net is my baseball team's website and after I click "photo albums" on the left of the screen and then click "2006 Baseball U Summer Team Pictures," all of the pictures in the album have that annoying red "x" next to them. I am unable to view the images. Guessing that the...
12
7491
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use it to reset info in a combo box. Below is some sample code for my view interface and the presenter: public interface IDevToolView
0
2017
by: raa abdullah | last post by:
Overview A conflict-serializbility\recoverability checker, SCR, is a program that takes in a schedule and outputs 2 decisions: Conflict serialzable or Not confilict serializable AND Recoverable or Not recoverable. The following is a detailed description of the program. Input The input to SCR should be a schedule of operations. It should be in a text file (.txt) where each line is in the following format: Operation TransactionNum ...
2
2092
by: Dave Ekhaus | last post by:
hi i'm new to javascript. i'm hoping to get some help and find out if what i want to do is possible and - assuming it is, get some tips on how to accomplish the task. ok - assume i have a table, the contents of which are dynamic. there can be any number of rows in this table - somewhere between 50 and 500 would be the range. in each row - there can be any number of td's. the relative 'width' of a td in a tr is specified by a td's...
0
8133
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8406
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5517
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4026
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2535
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1676
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1393
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.