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
windows
xml
grok
jpa
developer-tools
time-complexity
linkedin
css3
case
components
socket.io
shiro
alsa
maxscript
echo
x264
nuget-package
special-characters
spin
renjin
entitymanager
mvc-mini-profiler
vuejs
template-engine
production
nodemcu
selinux
ag
undertow
ksh
squashfs
systemtime
zxing
monit
interpreter
dynamically-generated
google-api-client
jboss6.x
shared
jackson-modules
exchangewebservices
cppreference
database-comparison
hibernate-validator
git-squash
android-gridview
arduino-ide
hivemq
xdocreport
bc
apns-php
doc
levenshtein-distance
skylink
android-ibeacon
sharp-snmp
install.packages
print-css
logback-groovy
chronicle-map
show-hide
httrack
openresty
tf
oracleclient
ngmaterial
seq
type-theory
stripe-connect
mapxtreme
signalr.client
jboss-tools
mapinfo
kango-framework
bizagi
redis-cluster
libav
jaunt-api
jnlua
jbase
assertion
xenomai
phonertc
dock
sony-lifelog-api
mod-proxy
zscript
viola-jones
uncompress
google-refine
zend-currency
dot.js
phpldapadmin
teaspoon
lambda-architecture
matrix-inverse
wxformbuilder
dot42
radiant
process-explorer
argouml
pstack
jdb
mapping-by-code
relative
rmdir
http-daemon
office-2007
aspmenu
ajax-polling
zend-rest
qtabbar
interop-domino
lemmatization

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App