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
delphi-7
c++11
linkedin
forms
jmeter
github-for-windows
yahoo-finance
rendering
rom
openstreetmap
commonjs
distribution
openbugs
supervisor
intercom
scrolltop
android-intent
docx
capistrano3
mvc-mini-profiler
sar
poedit
postscript
mongoid6
direct3d11
strongname
gpio
mat
ceylon
python-2.6
deltaspike
git-squash
clickjacking
jett
sammy.js
contacts
hunspell
sql-delete
baidu-map
hivemq
apic
openproject
watchman
flatmap
odoo-website
android-exoplayer
optimizely
xbmc
wcftestclient
mschart
azure-cli
compiler-design
arules
check-mk
oozie-coordinator
d3-force-directed
structuremap4
android-instrumentation
file-uri
vorpal.js
appscale
cfchart
kango-framework
lua-telegram-bot
query-by-example
ikiwiki
libav
findfirst
boomerang
jdi
intel-c++
opserver
iced-coffeescript
eoferror
grouping-sets
structuremap3
entry-point
raygun
xml-namespaces
ss7
model-driven-development
ebay-lms
tlf
cnf
pclzip
tree-balancing
extconf.rb
koken
objective-j
resharper-6.0
ie-compatibility-mode
request-headers
build-environment
silverlight-oob
web-application-project
interop-domino
cldc
movieplayer

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