dllimport


Declare and <DllImport> in VB.NET have different results


I've been trying to call a login method of an unmanaged DLL.
If I use Declare the login fails.
Private Declare Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32
Login ("Steve", "123456") ' THIS FAILS TO LOGIN ALTHOUGH THE PARAMS ARE CORRECT
If I use DllImport, it works !!
<DllImport("dllCore.dll",
EntryPoint:="Login",
SetLastError:=True,
CharSet:=CharSet.Unicode,
ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)>
Private Function Login(ByVal username As String, ByVal password As String) As Integer
End Function
Login ("Steve", "123456") ' NOW WORKS
Has anyone any ideas why I get this behaviour ??
The default character set for a Declare statement is Ansi. You need to set the charset to Unicode to properly match the DllImport.
Private Declare Unicode Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32
MSDN documentation for the Declare statement

Related Links

Mangled member function name different during dllimport
how to use DllImport in metro-style app
Converting doc file to post script
How can I get a COM component which can be used on Windows phone 8 project with C#
Externs and DLL imports
Mixed native and managed code heap corruption
MarshalDirectiveException
call unmanaged C++ code from C# using pinvoke
Detecting DLL Code Splicing
WOW64 Redirection and LoadLibrary
Using C# dll in Windows phone 7
Python 2.5 Import dll AttributeError
Replacing the Import Table in PE file by standart LoadLibrary
Unresolved external symbol
Declare and <DllImport> in VB.NET have different results
how to import/export dll and use its function

Categories

HOME
android
cygwin
porting
adal
deep-learning
cheerio
pda
error-handling
sublimetext
rendering
nested-if
frontend
vert.x
modal-dialog
arangodb
jquery-ui-sortable
cmdb
spring-social
gkturnbasedmatch
atlassian-stash
jersey-1.0
git-extensions
sencha-touch
selinux
visual-glitch
ksh
cgbitmapcontext
displaytag
has-and-belongs-to-many
gp
realm-mobile-platform
powershell-ise
cart
deltaspike
fstream
rselenium
carriage-return
least-squares
z-notation
trigonometry
preloader
movilizer
install.packages
http-request
berkeley-db-je
signal-strength
opencmis
globalize
context-switch
payload
bootstrap-tags-input
materialized-path-pattern
slackware
ziparchive
segment-io
watch-os-2
greatest-n-per-group
android-dateutils
angular-ui-typeahead
kendo-upload
jparsec
httpruntime.cache
contentcontrol
concept-insights
java-money
computer-architecture
keyup
mmwormhole
public-html
procedural-programming
execve
entry-point
jqmodal
winginx
vbe
square-bracket
multiautocompletetextview
ora-06550
visual-studio-express
away3d
mbunit
script#
beaker-testing
cmmi
ui-select2
process-explorer
wp7test
kqueue
cross-database
infobright
pinch
landscape-portrait
google-floodlight
pylucene
clrstoredprocedure
inline-formset
appledoc
non-clustered-index
opml
skype4java

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App