using DLL from Visual C++.net

  • Thread starter Thread starter Maileen
  • Start date Start date
M

Maileen

Hi,

I've created 2 dll with VC++.net, which are only resource dlls.
in fact, only strings are inside.

IDS_String101 101 Welcome
IDS_String102 102 Bye

where IDS_Stringxxx is the ID, 101 is the valueID and Welcome the value of this string

to load and display resource string dll value, here is my code :

' Load the Resource DLL
hLibrary = LoadLibrary("myapp\english.dll")
If hLibrary = 0 Then
MsgBox "Failed to load the specified library with error code " & Err.LastDllError
Exit Sub
End If
' Get a string from the Resource DLL
dim strString as string
dim lngStringLen as Long
lngStringLen = LoadString(hLibrary, 101, strString, Len(strString))
Form1.Label1.Text = Left(strString, lngStringLen)

but an error occur on :
lngStringLen = LoadString(hLibrary, 101, strString, Len(strString))

something like systemNull.xxxx
why ?

thanks a lot,
Maileen
 
thanks a lot,

but i place resources in this DLL, and how to get them from this DLL to my VB application ?

thanks a lot,
Maileen
 
Hi Maileen,

I see that you use Long for a return value of LoadString, so you
probably use bad Declare statements.
Try this sample instead:

~
Friend Declare Auto Function LoadLibrary Lib "kernel32.dll" ( _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpFileName As
String _
) As IntPtr
Friend Declare Auto Function LoadString Lib "user32.dll" ( _
ByVal hInstance As IntPtr, _
ByVal uID As Integer, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpBuffer As
System.Text.StringBuilder, _
ByVal nBufferMax As Integer _
) As Integer
Friend Declare Function FreeLibrary Lib "kernel32.dll" ( _
ByVal hModule As IntPtr _
) As Boolean

Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
Dim hMSGina As IntPtr =
LoadLibrary(Environment.ExpandEnvironmentVariables("%WINDIR%\System32\ms
gina.dll"))
Dim MyString As New System.Text.StringBuilder(256)
LoadString(hMSGina, 1525, MyString, MyString.Capacity)
FreeLibrary(hMSGina)
MessageBox.Show(MyString.ToString)
End Sub
~

I hope it helps,
Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top