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

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
HELP linking library in DLL project

Categories

HOME
developer-tools
eslint
fpga
rsa
gradient
ms-access-2016
soa
parameters
telegram-bot
visual-studio-emulator
vert.x
g++
reactive-programming
openpyxl
fhir
watson-conversation
redis-sentinel
datastage
tput
intercom
plink
flash-player
dimensional-modeling
dreamweaver
template-engine
pagespeed
dataflow-diagram
interpreter
game-theory
dapper-extensions
corpus
gp
zend-debugger
dumpbin
code-snippets
hibernate-search
slacktextviewcontroller
roblox
searchkit
hivemq
xcode7.3
zoomify
ods
kill
visa
attributeerror
wmp
bindingnavigator
show-hide
jide
dtsearch
configurationmanager
posixct
carrot2
azure-cli
filehandle
swingworker
visual-studio-2008-sp1
node-request
pytables
watch-os-2
macaulay2
lua-telegram-bot
spreadjs
yajsw
httpruntime.cache
mobiledoc-kit
themoviedb-api
flock
toolkit
sony-lifelog-api
batik
jsvc
uvc
mass-assignment
execve
webmatrix-3
tinyxml
vsx
ora-06550
mt4j
ice-cube
server-administration
sentestingkit
qtconcurrent
xcode3.2
httponly
clrstoredprocedure
appledoc
diagrams
timertask
delimited-text
facebook-iframe
request-headers
purepdf
image-capture

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