Re: "As Any" declaration???
hmm Ive never heard of that, but if you declare something as Object then you can set it to any type of object.
Re: "As Any" declaration???
Aethiest,
That seemed to work for now. I will know for sure when I start testing!
Thanks,
Re: "As Any" declaration???
As Any can generally be replaced with a general Object type, I have done it before... However, I think that if you know what object it will be returning and put that type into it (whether its some other API structure or whatever) it should work as well... as long as you always know what type it will return for what you are using it for...
Re: "As Any" declaration???
You should never use As Any in VB6 because it it denies the compiler the ability to do strong type checking on your code.
In VB.Net you should create one overloaded declaration for each parameter type you can pass.
Re: "As Any" declaration???
I never created the statement. This was a downloaded procedure to read and retrieve INI info.
I don't understand what you mean on your last statement by overloaded declaration statement.
Re: "As Any" declaration???
He means that if your argument can take multiple types then you should declare multiple overloads, one for each type. It's quite possible to declare many API functions with multiple signatures. For instance, where a handle is required you could declare an Integer or an IntPtr.
Re: "As Any" declaration???
Re: "As Any" declaration???
For example try writing this in VB:
VB Code:
Dim sr as new StreamReader(
Intellisense will show this:
http://img440.imageshack.us/img440/3646/intelliiy8.jpg
As you can see, there are 10 overloaded "New" subroutines of the StreamReaders. That means that there are 10 "New" subroutines that does the same thing, with different arguments that can be passed. If you press up and down the arrows you can see the different overloads.
Bah..this explanation was pretty crap, hope you get the point anyways. :cool:
Re: "As Any" declaration???
If you post up the VB6 declaration you want to convert we'll give you an example using that declaration...
Re: "As Any" declaration???
Here is the API call that contains the "As Any"
VB Code:
Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As any, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Re: "As Any" declaration???
When you call that API what do you pass as arguments on the "as any" arguments?
Re: "As Any" declaration???
That call came from a generic module that opened and retrieved INI values. The program that used that module never made a call to it.
Re: "As Any" declaration???
Looks like all should just be strings, and the Long changed to Int32... like below:
VB Code:
Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Int32
In the code sample in this MSDN Link, they were passing in strings...
Re: "As Any" declaration???
According to the MSDN[ documentation there are two ways of using this function.
One uses string parameters the other wants NULL.
To cater for this in VB.Net you write two overloaded declarations thus:-
VB Code:
Private Overloads Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Int32
Private Overloads Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As IntPtr, _
ByVal lpKeyName As IntPtr, _
ByVal lpString As IntPtr, _
ByVal lpFileName As String) As Int32