VB.net 2000
Windows XP only
I have an app that (among other things) allows the user to create a new
"phonebook" entry. API is defined this way:
Declare Auto Function RasCreate Lib "Rasapi32.dll"_ Alias
"RasCreatePhonebookEntry" (ByVal hwnd As Integer,_
<MarshalAs(UnmanagedType.LPStr)> Byval lpszPhonebook As String) As Integer
(I use the same MarshalAs directive for the RASSETCREDENTIALS API and it
works perfectly.)
If I pass vbnull as the phonebook name like this:
APIResult = RasCreate(Me.Handle.ToInt32, VBNULL)
it works fine, but the entry is always created in the "All Users" phonebook.
I want the user to be able to select the private phonebook if he wants, so I
need to pass the phonebook name as a variable.
I use:
dim phonebook as string
dim APIResult as integer
phonebook =
Environment.GetFolderPath_(Environment.SpecialFold er.CommonApplicationData)_
& "\Microsoft\Network\Connections\Pbk\rasphone.p bk"
or:
phonebook =
Environment.GetFolderPath_(Environment.SpecialFold er.ApplicationData)_ &
"\Microsoft\Network\Connections\Pbk\rasphone.p bk"
depending on if the user wants the public or private phonebook. Then:
APIResult = RasCreate(Me.Handle.ToInt32, phonebook)
always returns "Error 621: The system could not open the phonebook file".
As I mentioned earlier, i use the exact same method to pass the phonebook to
RasSetCredentials and it works fine.
What am I missing? 6 3459
Well I got it to work, but I'm as confused as ever. Maybe someone can explain
this.
I got it to work by leaving out the <marshalas..> directive so the delare is
just:
Declare Auto Function RasCreate Lib "Rasapi32.dll"_
Alias "RasCreatePhonebookEntry" (ByVal hwnd As Integer,_
Byval lpszPhonebook As String) As Integer
I'm confused because leaving out the <marshalas...> directive has caused an
error with every other RAS api i've used when passing a string variable. Can
anyone out there explain why RasCreatePhonebookEntry is different?
"Doug Robertson" wrote: VB.net 2000 Windows XP only
I have an app that (among other things) allows the user to create a new "phonebook" entry. API is defined this way:
Declare Auto Function RasCreate Lib "Rasapi32.dll"_ Alias "RasCreatePhonebookEntry" (ByVal hwnd As Integer,_ <MarshalAs(UnmanagedType.LPStr)> Byval lpszPhonebook As String) As Integer
(I use the same MarshalAs directive for the RASSETCREDENTIALS API and it works perfectly.)
If I pass vbnull as the phonebook name like this:
APIResult = RasCreate(Me.Handle.ToInt32, VBNULL)
it works fine, but the entry is always created in the "All Users" phonebook. I want the user to be able to select the private phonebook if he wants, so I need to pass the phonebook name as a variable.
I use: dim phonebook as string dim APIResult as integer
phonebook = Environment.GetFolderPath_(Environment.SpecialFold er.CommonApplicationData)_ & "\Microsoft\Network\Connections\Pbk\rasphone.p bk"
or:
phonebook = Environment.GetFolderPath_(Environment.SpecialFold er.ApplicationData)_ & "\Microsoft\Network\Connections\Pbk\rasphone.p bk"
depending on if the user wants the public or private phonebook. Then:
APIResult = RasCreate(Me.Handle.ToInt32, phonebook)
always returns "Error 621: The system could not open the phonebook file".
As I mentioned earlier, i use the exact same method to pass the phonebook to RasSetCredentials and it works fine.
What am I missing?
Doug, I'm confused because leaving out the <marshalas...> directive has caused an error with every other RAS api i've used when passing a string variable. Can anyone out there explain why RasCreatePhonebookEntry is different?
The Auto modifier will cause the CLR to call the Unicode version of
the API on NT-based systems (which I assume you're running on), but
using MarshalAs(UnmanagedType.LPStr) will cause the string parameter
to marshal as an ANSI string. And passing an ANSI string to a function
expecting a Unicode string will of course not work. You could have
used MarshalAs(UnmanagedType.LPTStr), but leaving out the MarshalAs
attribute and relying on the default behavior works just as well.
BTW, I recommend changing the type of the hwnd parameter to IntPtr.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
So since this is strictly for our internal use and I don't care if it handles
unicode strings, would i be better off not using the Auto modifier and just
explicitly specifing Ansi?
"Mattias Sjögren" wrote: Doug,
I'm confused because leaving out the <marshalas...> directive has caused an error with every other RAS api i've used when passing a string variable. Can anyone out there explain why RasCreatePhonebookEntry is different?
The Auto modifier will cause the CLR to call the Unicode version of the API on NT-based systems (which I assume you're running on), but using MarshalAs(UnmanagedType.LPStr) will cause the string parameter to marshal as an ANSI string. And passing an ANSI string to a function expecting a Unicode string will of course not work. You could have used MarshalAs(UnmanagedType.LPTStr), but leaving out the MarshalAs attribute and relying on the default behavior works just as well.
BTW, I recommend changing the type of the hwnd parameter to IntPtr. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
NOW I get it!
On all my other API declarations, I had explicity listed the Ansi version in
the alias parameter (e.g. alias "RasSetCredentialsA") on this one I left off
the "A" in the alias. That's why I had to use the <MarshalAs...> directive on
the other calls to force an Ansi string.
Live and learn.
"Doug Robertson" wrote: So since this is strictly for our internal use and I don't care if it handles unicode strings, would i be better off not using the Auto modifier and just explicitly specifing Ansi?
"Mattias Sjögren" wrote:
Doug,
I'm confused because leaving out the <marshalas...> directive has caused an error with every other RAS api i've used when passing a string variable. Can anyone out there explain why RasCreatePhonebookEntry is different?
The Auto modifier will cause the CLR to call the Unicode version of the API on NT-based systems (which I assume you're running on), but using MarshalAs(UnmanagedType.LPStr) will cause the string parameter to marshal as an ANSI string. And passing an ANSI string to a function expecting a Unicode string will of course not work. You could have used MarshalAs(UnmanagedType.LPTStr), but leaving out the MarshalAs attribute and relying on the default behavior works just as well.
BTW, I recommend changing the type of the hwnd parameter to IntPtr. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. So since this is strictly for our internal use and I don't care if it handles unicode strings, would i be better off not using the Auto modifier and just explicitly specifing Ansi?
No, I definitely recommend using Auto.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
I just finished creating a RAS wrapper for the .NET framework with
(hopefully) all RAS functionality for outgoing connections. It can be found
at: http://www.gotdotnet.com/Workspaces/...3-e5fdb0895b8e
If you find any bugs, please report them so they can be addressed.
Thanks
"Doug Robertson" wrote: VB.net 2000 Windows XP only
I have an app that (among other things) allows the user to create a new "phonebook" entry. API is defined this way:
Declare Auto Function RasCreate Lib "Rasapi32.dll"_ Alias "RasCreatePhonebookEntry" (ByVal hwnd As Integer,_ <MarshalAs(UnmanagedType.LPStr)> Byval lpszPhonebook As String) As Integer
(I use the same MarshalAs directive for the RASSETCREDENTIALS API and it works perfectly.)
If I pass vbnull as the phonebook name like this:
APIResult = RasCreate(Me.Handle.ToInt32, VBNULL)
it works fine, but the entry is always created in the "All Users" phonebook. I want the user to be able to select the private phonebook if he wants, so I need to pass the phonebook name as a variable.
I use: dim phonebook as string dim APIResult as integer
phonebook = Environment.GetFolderPath_(Environment.SpecialFold er.CommonApplicationData)_ & "\Microsoft\Network\Connections\Pbk\rasphone.p bk"
or:
phonebook = Environment.GetFolderPath_(Environment.SpecialFold er.ApplicationData)_ & "\Microsoft\Network\Connections\Pbk\rasphone.p bk"
depending on if the user wants the public or private phonebook. Then:
APIResult = RasCreate(Me.Handle.ToInt32, phonebook)
always returns "Error 621: The system could not open the phonebook file".
As I mentioned earlier, i use the exact same method to pass the phonebook to RasSetCredentials and it works fine.
What am I missing?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hubert Baumeister |
last post by:
Fifth International Conference on
eXtreme Programming and Agile Processes
in Software Engineering
XP2004
June 6-10, 2004, Garmisch-Partenkirchen, Germany
http://www.xp2004.org/
|
by: Marwan |
last post by:
Hello
I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking.
If i put the thread to sleep in my...
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: mitchellpal |
last post by:
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?
|
by: shsingh |
last post by:
I have a class A containing some map as data variables. I creat an
object of class A on heap by allocatiing memory by using "malloc". This
will return me the required memory but the object is not...
|
by: cberthu |
last post by:
Hi all,
Is it possible to have two connects in the same rexx script to
different DB's?
I have to get data form on DB (with specifics selects and filter out
some values with RExx) and save the...
|
by: CryptiqueGuy |
last post by:
Consider the variadic function with the following prototype:
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this...
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |