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

Cannot create automation object - lotusscript
DllImport is not found C++
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

Categories

HOME
uml
asp.net-web-api
localization
deep-learning
forms
dns
amp-html
pda
ns-3
jmx
rendering
switch-statement
3d-reconstruction
visual-studio-emulator
onclick
azure-container-service
arangodb
syntaxnet
ibeacon-android
plist
resultset
libc
intercom
eip
3nf
android-intent
symfony-2.8
dreamweaver
jersey-1.0
smartclient
bourbon
apache2.4
articulate-storyline
spring-async
jquery-ias
dataflow-diagram
monit
perlbrew
surveymonkey
jackson-modules
handler
corenlp-server
clickjacking
reactjs.net
roblox
raft
xdocreport
protein-database
projects-and-solutions
jvmti
stringtokenizer
apriori
contract
android-checkbox
openresty
qtranslate
java-6
libjpeg
type-theory
java-websocket
android-instrumentation
change-tracking
node-request
reporting-services-2012
resourcemanager
dimension
cfchart
gcloud-ruby
uiactionsheet
findfirst
pushbots
jparsec
contentcontrol
design-principles
phpgrid
tfs-workitem
jdi
viola-jones
graphics2d
aspectj-maven-plugin
matlab-deployment
uvc
cakephp-2.7
procedural-programming
grouping-sets
pseudo-class
sip-server
webfinger
gii
insight.database
draw2d-js
sbcl
android-usb
ora-06550
route-provider
abstract-data-type
joomla-template
mysql-error-2013
twisted.web
argouml
web-notifications
iboutlet
window-decoration
usertype
user-tracking
fsevents
quotation-marks
undefined-index
zend-rest
tabpanel
lxr
silverlight-oob
cuda.net
asynchronous-wcf-call
localizable.strings
blind
netbeans6.1

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